#10913: Default related_name is broken
-------------------------------------+-------------------------------------
Reporter: neithere | Owner: nobody
Type: | Status: reopened
Uncategorized | Component: Database layer
Milestone: | (models, ORM)
Version: SVN | Severity: Normal
Resolution: | Keywords: orm, related_name,
Triage Stage: | Has patch: 0
Unreviewed | Needs tests: 0
Needs documentation: 0 | Easy pickings: 0
Patch needs improvement: 0 |
UI/UX: 0 |
-------------------------------------+-------------------------------------
Changes (by Greg Brown <greg@…>):
* status: closed => reopened
* severity: => Normal
* cc: greg@… (added)
* resolution: invalid =>
* easy: => 0
* ui_ux: => 0
* type: => Uncategorized
Comment:
I think the OP is correct here, at least in that the ORM is inconsistent.
The docs state that the default related name is {{{FOO_set}}}, and while
this is true when accessing the manager, the OP gets differing behaviour
when explicitly setting {{{related_name='book_set'}}} to the default when
filtering (as do I). To spell it out again, the following will work:
{{{
class Event(models.Model):
...
class Image(models.Model):
event = models.ForeignKey(Event, related_name='image_set')
>>> Event.objects.filter(image_set__isnull=True)
}}}
Whereas this will throw a {{{FieldError}}}:
{{{
class Event(models.Model):
...
class Image(models.Model):
event = models.ForeignKey(Event)
>>> Event.objects.filter(image_set__isnull=True)
}}}
This ticket does not indicate "a misunderstanding about Django, how it
works, and how to use it"; rather it points out a gotcha that needs to be
fixed, or at the very least properly documented.
--
Ticket URL: <https://code.djangoproject.com/ticket/10913#comment:2>
Django <https://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.