0

I have this serializer:

class ProjectSerializer(serializers.HyperlinkedModelSerializer):

class Meta:
    model = Project
    fields = ('id', 'name', 'project_id', 'user_set')
    read_only_fields = ('created', 'modified')

Then I have a form which is derived from this answer. This is the code from it that I think is relevant:

user_set = forms.ModelMultipleChoiceField(queryset=User.objects.all())

You might already see the problem. The API expects HyperLinkedModels to be passed, but instead I pass plain User objects. So posting the form results in this error:

"user_set": [
    "Invalid hyperlink - No URL match."
]

I could edit the serializer to not expect a HyperLink but I would like to maintain that functionality. How can I parse the result from the queryset as HyperLinkedModels? Or how do I make it return HyperLinkedModels from the get go?

Is there an easy way to do this?

Snackoverflow
  • 736
  • 9
  • 31

0 Answers0