0๐
โ
Had to handle this error by updating to_representation method on the PrimaryKeyRelatedField class
class NodePrimaryKeyField(serializers.PrimaryKeyRelatedField):
"""
Custom DRF serializer field for proper handling of
Node Foreign Key by ListSerializer on validation error
"""
def to_representation(self, value):
"""
Return pk value of serialized Node object
if available else return given ID value
"""
if self.pk_field is not None:
return self.pk_field.to_representation(value.pk)
return getattr(value, 'pk', value)
๐คbbmhmmad
0๐
The serializer.data
property is only valid if you have a saved an instance to the serializer.
Either call serializer.save()
or use serializer.validated_data
to access data prior to saving.
Checkout this link for further information.
๐คRene B.
- [Django]-How can I create sophisticated Django Model Validation for Django Admin?
- [Django]-Force re-collectstatic with django static?
- [Django]-Django localization: labels don't get updated
Source:stackexchange.com