* 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.
* status: closed => reopened
* severity: => Normal
* type: => Uncategorized
* easy: => 0
* ui_ux: => 0
* resolution: invalid =>
Comment (by gregplaysguitar):
Sorry about that, I was getting gateway timeouts so hit refresh a couple
of times.
--
Ticket URL: <https://code.djangoproject.com/ticket/10913#comment:3>
* needs_docs: 0 => 1
* type: Uncategorized => Cleanup/optimization
* component: Database layer (models, ORM) => Documentation
* stage: Unreviewed => Accepted
Comment:
The code example you provide is working as intended. However, I'll accept
this ticket as a documentation issue; a quick scan of the related_name
docs didn't reveal anything describing this behavior.
--
Ticket URL: <https://code.djangoproject.com/ticket/10913#comment:4>
Comment (by gregplaysguitar):
Fair enough, thanks for the quick response.
--
Ticket URL: <https://code.djangoproject.com/ticket/10913#comment:5>
* status: new => assigned
* owner: nobody => timo
--
Ticket URL: <https://code.djangoproject.com/ticket/10913#comment:7>
* status: assigned => closed
* resolution: => fixed
Comment:
In [changeset:"75bb6ba96660e2a06e18d99120c05db2bb9fa9cc"]:
{{{
#!CommitTicketReference repository=""
revision="75bb6ba96660e2a06e18d99120c05db2bb9fa9cc"
Fixed #10913 -- Documented how related_name affects QuerySet filtering
Thanks neithere for the suggestion.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/10913#comment:8>
Comment (by Tim Graham <timograham@…>):
In [changeset:"06b149e220f98cd643a4445db1b5719daac0d56f"]:
{{{
#!CommitTicketReference repository=""
revision="06b149e220f98cd643a4445db1b5719daac0d56f"
[1.6.x] Fixed #10913 -- Documented how related_name affects QuerySet
filtering
Thanks neithere for the suggestion.
Backport of 75bb6ba966 from master
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/10913#comment:9>