#2316: GenericRelation and get_or_create do not work together
-----------------------------+----------------------------------------------
Reporter: Rudolph | Owner: adrian
Type: defect | Status: new
Priority: normal | Milestone: Version 1.0
Component: Admin interface | Version: SVN
Severity: normal | Resolution:
Keywords: |
-----------------------------+----------------------------------------------
Comment (by David Danier <[EMAIL PROTECTED]>):
If I see this right this does not work with any operation (get, filter,
exclude, ...) and is so far not intended to be used this way.
(I think this bug targets models.GenericForeignKey, as there is no code-
example provided)
Ugly workaround (thats the reason I posted in the first place ;-):
from django.contrib.contenttypes.models import ContentType
baz =
Bar.objects.get_or_create(content_type=ContentType.objects.get_for_model(foo.__class__),
object_id=getattr(foo, foo.__class__._meta.pk.column))
Somehow nicer (but unflexible in this form):
def do_generic_stuff(func, obj):
from django.contrib.contenttypes.models import ContentType
content_type = ContentType.objects.get_for_model(obj.__class__)
object_id = getattr(obj, obj.__class__._meta.pk.column)
return func(content_type=content_type, object_id=object_id)
# call:
baz = do_generic_stuff(Bar.objects.get_or_create, foo)
--
Ticket URL: <http://code.djangoproject.com/ticket/2316#comment:>
Django <http://code.djangoproject.org/>
The web framework for perfectionists with deadlines.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Django
updates" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/django-updates?hl=en
-~----------~----~----~----~------~----~------~--~---