My serializers.py file:

from rest_framework import serializers

    from diagnosisApp.models import Question, Option


    class OptionSerializer(serializers.ModelSerializer):

        class Meta:
            model = Option
            fields = ('id', 'content')


    class QuestionSerializer(serializers.Serializer):
        content = serializers.CharField()
        options = OptionSerializer(
            Option.objects.filter(optiongroup__question=**insert instance 
value here**).distinct(),
            many=True
            )

I'm trying to create a nested OptionSerializer inside QuestionSerializer 
but I need to filter the queryset based on the question instance which will 
be passed during initialization in this section: 
`optiongroup__question=**insert instance value here**`. How do I do this?

P.S: Please don't tell me to use ModelSerializer or SerializerMethodField 
because options is not directly related to Question and the options field 
needs to be writable.

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-rest-framework/11b7939f-caef-420d-bcd3-21b4f56d80f0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to