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

Popular posts from this blog

Verilog Error: output or inout port "Q" must be connected to a structural net expression -

jasper reports - How to center align barcode using jasperreports and barcode4j -

c# - ASP.NET MVC - Attaching an entity of type 'MODELNAME' failed because another entity of the same type already has the same primary key value -