Let's say we have model Travel with many related fields:
class Travel(models.Model):
tags = models.ManyToManyField(
Tag,
related_name='travels', )
route_places = models.ManyToManyField(
RoutePlace,
related_name='travels', )
coordinate = models.F...
Nested serializers by default don't support create and update. To support this without duplicating DRF create/update logic, it is important to remove the nested data from validated_data before delegating to super:
# an ordinary serializer
class UserProfileSerializer(serializers.ModelSerializer):
...
In DRF, serializer validation is run in a specific, undocumented order
Field deserialization called (serializer.to_internal_value and field.run_validators)
serializer.validate_[field] is called for each field.
Serializer-level validators are called (serializer.run_validation followed by seriali...
Assume that, we implement a simple API and we have the following models.
class Parent(models.Model):
name = models.CharField(max_length=50)
class Child(models.Model):
parent = models.ForeignKey(Parent)
child_name = models.CharField(max_length=80)
And we want to return a respo...