I've been writing a few NestedSerializers lately, and coming across as 
having too much unnecessary boilerplate. I think there's an opportunity to 
streamline in a way to serves almost the same use case, but vastly 
Best demonstrated with an example:

Suppose I have the following 2 models

class ContactDetails(models.Model):
    person = models.OneToOneField(Person)
    email = models.CharField()


class Person(models.Model):
    first_name = models.CharField()
    last_name = models.CharField()

Currently, if I want an API that can edit the person's email, i need to 
write a PersonSerializer, a ContactDetailsSerializer and link them using a 
NestedSerializer. I see a much simpler way of implementing this, using 
conventions that django developers are already familiar with. Something 
like this:

class PersonSerializer(serializers.ModelSerializer):
    class Meta:
        model = Person
        fields = ('id', 'first_name', 'last_name', 'contactdetails__email')

Has this been considered and discarded for some reason? I would love to dig 
into it and see if there's a way to get a lot of the benefit here to 
address simple use cases into a third-party package.



You received this message because you are subscribed to the Google Groups 
"Django REST framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-rest-framework+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to