django - How to choose specific columns when using depth in serializer -
I have a model that consists of two ForeignKeys I only
ForeignKeys , so I am using the
depth variable, which originally gives me all columns of tables referred to by FK. What column should a column include to select? Class SomeSerializer (serializers.ModelSerializer): Class Meta: Model = MyAwesomeModel fields = ('id', 'fk_one', 'fk_two') Depth = 1
Try using the nested serializer documentation
Example:
class FKOneSerializer (serializers.ModelSerializer): class meta: model = FKOne fields = ('name', 'id') class SomeSerializer (serializers.ModelSerializer): fk_one = FKOneSerializer () class meta: model = MyAwesomeModel fields = ( 'id', 'fk_one', 'fk_two') Edit:
Similar reply creator of Django Relief Framework It also includes some related notes in which nested serializers are read-only and you may have to include a source argument on the serializer field.
Comments
Post a Comment