support for generic relations #101

Closed
tiabas opened this Issue Mar 13, 2011 · 3 comments

3 participants

@tiabas

I was wondering if there is an easy way to handle generic relationship for models that possess them. Right now, I'm using a hack by making a model resource for Django's builtin Contenttype model and then subsequently making queries that use app_label & object_id inorder to retrieve an object using tastypie.

something like this:

from django.contrib.contenttypes.models import ContentType

class ContentTypeResource(ModelResource):
class Meta:
queryset = ContentType.objects.all()
resource_name = 'contenttypes'
fields = ['model']
detail_allowed_methods = ['get',]
list_allowed_methods = ['get']

@dhatch

Check out this pull request which contains code i've written to nicely support this.

@tiabas

Thanks!!

@issackelly issackelly added a commit that referenced this issue Aug 28, 2012
@issackelly issackelly Added GenericForeignKey support.
Thanks for the original patch @achur (Alex Churchill)
Thanks for reporting @tiabas (Kevin Mutyaba), @dhatch (David Hatch)
Thanks @joshbodhe and @toastdriven for the code review and support.

Closes Issue #101
Closes Issue #191

This was resolved and added with issue #620.

Squashed commit of the following:

commit eb87af0
Author: Issac Kelly <issac.kelly@gmail.com>
Date:   Mon Aug 27 22:58:16 2012 -0700

    Remove unused file and empty tests file. Resources are tested via the fields.py file

commit 00453c1
Author: Issac Kelly <issac.kelly@gmail.com>
Date:   Mon Aug 27 22:53:24 2012 -0700

    Whitespace

commit 67298f4
Author: Issac Kelly <issac.kelly@gmail.com>
Date:   Mon Aug 27 22:39:44 2012 -0700

    Add Docs.

commit 179ab3f
Author: Issac Kelly <issac.kelly@gmail.com>
Date:   Mon Aug 27 21:17:10 2012 -0700

    Fix field init tests. Thanks Josh Bohde

commit 7b37078
Author: Issac Kelly <issac.kelly@gmail.com>
Date:   Mon Aug 27 21:00:29 2012 -0700

    Whitespace cleanup and comments.

commit 02988b0
Author: Issac Kelly <issac.kelly@gmail.com>
Date:   Mon Aug 13 23:28:01 2012 -0700

    WIP contenttypes/GFK integration.

    Needs:
    more thought about tests
    code review
    release notes
    documentation
    gracious thanking of the people who helped
    Python 2.5 solution for context managers in tests.
f5ae8bf
@georgedorn

Looks like this got added in #620.

@georgedorn georgedorn closed this Apr 9, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment