class FooSerializer(ModelSerializer):
bar = SerializerMethodField('get_bar')
def get_bar(self, obj):
req = self.context['request']
if(req.method == 'GET'):
bar = BarSerializer(many=True) # shouldn't I pass the data related to 'Bar' here?
else:
bar = PrimaryKeyRelatedField(many=True, queryset=Bar.objects.filter(foo=obj)) # is this correct?
# insert class Meta here...