class Foo(models.Model):
bar = models.CharField(max_length=300)
content_type = models.ForeignKey(ContentType)
object_id = models.PositiveIntegerField()
content_object = GenericForeignKey('content_type', 'object_id')
class FooSerializer(serializers.ModelSerializer):
class Meta:
model = Foo
class FooViewSet(viewsets.ModelViewSet):
model = Foo
serializer_class = FooSerializer
I can now post data to the viewset that looks like this:
{
bar: 'content',
content_type: 1
object_id: 5
}
The only thing that's bugging me is that the frontend would have to be aware of the contenttype id's
Instead I want to be able to post the content_types name like 'User' as content_type and have the backend determine the id.