I seem to be having trouble getting Schema for nested serializers to show
up.
>From django rest swagger, this is what is seen as my schema:
{
"prop1": "string",
"prop2": "string",
"prop3": "string",
"options": [
"string"
]
}
but I am expecting something like:
{
"prop1": "string",
"prop2": "string",
"prop3": "string",
"options": [
{
"prop1": "string",
"prop2": "string"
}
]
}
My serializers look like this:
class NewOptionSerializer(serializers.HyperlinkedModelSerializer):
class Meta:
model = Option
fields = ('prop1', 'prop2')
class NewMyModelSerializer(serializers.HyperlinkedModelSerializer):
options = OptionSerializer(many=True)
class Meta:
model = MyModel
fields = ('prop1', 'prop2', 'prop3', 'options')
def create(self, validated_data):
options = validated_data.pop('options')
mymodel = MyModel.objects.create(**validated_data)
if options:
for option in options:
Option.objects.create(mymodel=mymodel, **option)
else:
# If there are no Options.. create the default set
# defaults created here
return mymodel
Thanks in advance for any help with regards to this.
-Jeff
--
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 [email protected].
For more options, visit https://groups.google.com/d/optout.