#7800: GenericRelation doesn't respect changes from the default
GenericForeignKey
field names in the contenttypes framework
-----------------------------------+----------------------------------------
Reporter: devinj | Owner: charmless
Status: assigned | Milestone:
Component: Contrib apps | Version: SVN
Resolution: | Keywords:
Stage: Accepted | Has_patch: 1
Needs_docs: 1 | Needs_tests: 1
Needs_better_patch: 1 |
-----------------------------------+----------------------------------------
Changes (by charmless):
* status: new => assigned
* needs_better_patch: 0 => 1
* needs_tests: 0 => 1
* owner: nobody => charmless
* needs_docs: 0 => 1
* has_patch: 0 => 1
Comment:
I've run into this as well. The nasty part is that it's not caught by
model validation, so everything seems fine until you use it.
The central issue is these lines in django/contrib/contenttypes/generic.py
(from line 114 in SVN 8279):
{{{
# Override content-type/object-id field names on the related class
self.object_id_field_name = kwargs.pop("object_id_field",
"object_id")
self.content_type_field_name = kwargs.pop("content_type_field",
"content_type")
}}}
These are two optional arguments not mentioned in the docs (that I can
find), which default to 'object_id' and 'content_type' for the two fields.
At the least, there should be some sort of validation error if a
GenericRelation tries to associate itself to a model without the
object_id/pk and content_type/ct fields it expects. These two fields would
also need to be documented.
Alternatively, I've got a bit of a nicer mechanism for this. I'll attach a
patch which lets you do such things as:
{{{
...
relname1 = GenericRelation(Blog) # connect to the only existing
GenericForeignKey on Blog, error if there isn't exactly one
relname2 = GenericRelation(Lifestream, from='item') # connects to the
GenericForeignKey named 'item' on the Lifestream model
...
}}}
I've added checks for any case where the connection is broken or
ambiguous. Comments appreciated!
--
Ticket URL: <http://code.djangoproject.com/ticket/7800#comment:4>
Django Code <http://code.djangoproject.com/>
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
-~----------~----~----~----~------~----~------~--~---