You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
so in update we have to pass instance to the serializer
I worked on it
` def to_internal_value(self, data):
"""
Deserialize data from translations fields.
For each received language, delegate validation logic to
the translation model serializer.
"""
if data is None:
return
if not isinstance(data, dict):
self.fail('invalid')
if not self.allow_empty and len(data) == 0:
self.fail('empty')
if self.shared_model is None:
return
# related_name = self.source or field_name
result, errors, = {}, {}
translated_model = self.shared_model.__dict__[self.source].field.model
for lang_code, model_fields in data.items():
if 'id' in model_fields:
instance = translated_model.objects.get(pk=model_fields['id'])
serializer = self.serializer_class(instance, data=model_fields, partial=self.parent.partial)
else:
serializer = self.serializer_class(data=model_fields)
if serializer.is_valid():
result[lang_code] = serializer.validated_data
else:
errors[lang_code] = serializer.errors
if errors:
raise serializers.ValidationError(errors)
return result`
so could you edit your code so it would work on update and partial update
The text was updated successfully, but these errors were encountered:
I have model translation include
fox ex : title , slug fields
the problem on update you get error when serializing data that field slug all ready exist
the cause of the problem in TranslatedFieldsField class in to_internal_value fun
serializer = self.serializer_class(data=model_fields)
so in update we have to pass instance to the serializer
I worked on it
` def to_internal_value(self, data):
"""
Deserialize data from translations fields.
so could you edit your code so it would work on update and partial update
The text was updated successfully, but these errors were encountered: