- Notifications
You must be signed in to change notification settings - Fork302
Closed
Labels
Description
Is GenericRelation support possible? This is how I would do it with Django rest. Can't get this to work however as I am getting theis not JSON serializable
error. Guessing there might be some serialization issue with json api?
# Serializerclass FooSerializer(serializers.ModelSerializer): included_serializers = { 'news': NewsSerializer, } class Meta: model = Foo fields = ('id', 'news')# News Serializerclass NewsSerializer(serializers.ModelSerializer): class Meta: model = News fields = ('id', 'description', 'date')# Foo Modelclass FooModel(models.Model): news = GenericRelation(News)# News Modelclass News(models.Model): id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False) description = models.TextField(max_length=200, blank=True) date = models.DateTimeField(blank=True, null=True) content_type = models.ForeignKey(ContentType) object_id = models.UUIDField() content_object = GenericForeignKey('content_type', 'object_id') class JSONAPIMeta: resource_name = 'news'
I'd be happy to add some "documentation" through the examples and work through it that way. That is of course if somebody has not already come across this!