Skip to content

GenericRelation Support #224

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
snewcomer opened this issue Apr 13, 2016 · 4 comments
Closed

GenericRelation Support #224

snewcomer opened this issue Apr 13, 2016 · 4 comments

Comments

@snewcomer
Copy link
Contributor

snewcomer commented Apr 13, 2016

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 the is not JSON serializable error. Guessing there might be some serialization issue with json api?

# Serializer
class FooSerializer(serializers.ModelSerializer):

    included_serializers = {
        'news': NewsSerializer,
    }

    class Meta:
        model = Foo
        fields = ('id', 'news')


# News Serializer
class NewsSerializer(serializers.ModelSerializer):

    class Meta:
        model = News
        fields = ('id', 'description', 'date')


# Foo Model
class FooModel(models.Model):
    news = GenericRelation(News)


# News Model
class 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!

@jerel
Copy link
Member

jerel commented Apr 14, 2016

I have not tried to use GenericForeignKey so it's possible that it's not implemented. If you want to open a PR with tests I'll happily review it

@patroqueeet
Copy link

+1

@snewcomer
Copy link
Contributor Author

@snewcomer
Copy link
Contributor Author

Any thoughts on getting Generic Relation support? Sry wish I could contribute but a bit overloaded right now (as we all are :) )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants