I'm not even sure how to write this question, but I want a writeable SlugRelatedField on a ModelSerializer. (
http://tomchristie.github.io/rest-framework-2-docs/api-guide/relations#slugrelatedfield) The queryset needs to be filtered for the value on another field of the Model. Is this even possible?
Here's some sample code to try and explain:
class MyModel(models.Model):
name = models.CharField()
thing1 = models.ForeignKey(MyModel2)
thing2 = models.ForeignKey(MyModel3)
class MyModel2(modles.Model):
name = models.CharField()
address = models.CharField()
phone = models.CharField()
class MyModel3(models.Model):
name = models.CharField()
value = models.DecimalField()
related = ForeignKey(MyModel2)
class MyModelSerializer(serializers.ModelSerializer):
thing2 = serializers.SlugRelatedField(slug_field='name', required=False, queryset=???)
I think I want object.thing1.mymodel3_set.all(), because I only want to choose from objects that match on the slug_field and related=object.thing1.