[Django] #18668: Make related_query_name more configurable

15 views
Skip to first unread message

Django

unread,
Jul 25, 2012, 1:42:23 PM7/25/12
to django-...@googlegroups.com
#18668: Make related_query_name more configurable
----------------------------------------------+--------------------
Reporter: zmsmith | Owner: nobody
Type: New feature | Status: new
Component: Database layer (models, ORM) | Version: 1.4
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
----------------------------------------------+--------------------
Using {{{related_name}}} for {{{accessor_name}}} and
{{{related_query_name}}} makes it difficult it mimic django's default
functionality with overridden attribute names.

For example, if I have a model {{{Foo}}} with a {{{ForeignKey}}} to
{{{Bar}}}, but I want {{{Bar}}} to interact with {{{Foo}}} as though it's
a model named {{{Fizz}}} there's no way to allow {{{Bar}}} to have an
attribute called {{{fizz_set}}} and query against the field {{{fizz}}}.

I believe this could be implemented easily and be backwards compatible by
giving {{{ForeignKey}}} and {{{ManyToManyField}}} additional key word
argument {{{related_query_name}}} that would be passed down to
{{{rel_class}}}. Then {{{get_query_name}}} could just check for the
existence of this value before returning either {{{related_name}}} or
{{{opts.object_name.lower()}}} as it currently does.

Are there any reasons not to do this? I couldn't find any prior discussion
in Trac.

--
Ticket URL: <https://code.djangoproject.com/ticket/18668>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Nov 13, 2012, 4:23:05 PM11/13/12
to django-...@googlegroups.com
#18668: Make related_query_name more configurable
-------------------------------------+-------------------------------------

Reporter: zmsmith | Owner: nobody
Type: New feature | Status: new
Component: Database layer | Version: 1.4
(models, ORM) | Resolution:
Severity: Normal | Triage Stage: Accepted
Keywords: | Needs documentation: 0
Has patch: 0 | Patch needs improvement: 0
Needs tests: 0 | UI/UX: 0
Easy pickings: 0 |
-------------------------------------+-------------------------------------
Changes (by aaugustin):

* needs_better_patch: => 0
* stage: Unreviewed => Accepted
* needs_tests: => 0
* needs_docs: => 0


Comment:

It took me quite some time to understand the problem described here, but I
think it's valid.

I'll rephrase it to ensure we're talking about the same thing, and for the
benefit of other contributors.

The OP's description translates to the following models:

{{{
from django.db import models

class Bar(models.Model):
pass

class Foo(models.Model):
name = models.CharField(max_length=100)
bar = models.ForeignKey(Bar)
}}}

With these definitions, you can do:

{{{
bar.foo_set.all()
Bar.objects.filter(foo__name__contains='xxx')
}}}

Now, if you add `related_name='fizz_set'` to the `ForeignKey` declaration,
you can do:

{{{
bar.fizz_set.all()
Bar.objects.filter(fizz_set__name__contains='xxx')
# ^^^^-- ugly!
}}}

And if you add `related_name='fizz'` it doesn't improve the situation:
{{{
bar.fizz.all()
# ^^^^-- ugly!
Bar.objects.filter(fizz__name__contains='xxx')
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/18668#comment:1>

Django

unread,
May 31, 2013, 4:32:35 PM5/31/13
to django-...@googlegroups.com
#18668: Make related_query_name more configurable
-------------------------------------+-------------------------------------

Reporter: zmsmith | Owner: nobody
Type: New feature | Status: new
Component: Database layer | Version: 1.4
(models, ORM) | Resolution:
Severity: Normal | Triage Stage: Accepted
Keywords: | Needs documentation: 0
Has patch: 1 | Patch needs improvement: 0

Needs tests: 0 | UI/UX: 0
Easy pickings: 0 |
-------------------------------------+-------------------------------------
Changes (by timo):

* has_patch: 0 => 1


Comment:

https://github.com/django/django/pull/693

--
Ticket URL: <https://code.djangoproject.com/ticket/18668#comment:2>

Django

unread,
Jul 30, 2013, 5:36:44 PM7/30/13
to django-...@googlegroups.com
#18668: Make related_query_name more configurable
-------------------------------------+-------------------------------------

Reporter: zmsmith | Owner: nobody
Type: New feature | Status: new
Component: Database layer | Version: 1.4
(models, ORM) | Resolution:
Severity: Normal | Triage Stage: Accepted
Keywords: | Needs documentation: 0
Has patch: 1 | Patch needs improvement: 1

Needs tests: 0 | UI/UX: 0
Easy pickings: 0 |
-------------------------------------+-------------------------------------
Changes (by timo):

* needs_better_patch: 0 => 1


Comment:

Part of what's included in the PR above was committed in
99b467f272da91b8894dc90d793d8d2c40b78d8c and
12cb0df10f12e715bcaafbee4290c92d4ed6f111. It looks like the PR contains
some things that weren't added (e.g. adding this on generic relations) but
it needs to be updated to merge cleanly.

--
Ticket URL: <https://code.djangoproject.com/ticket/18668#comment:3>

Django

unread,
Mar 5, 2014, 9:54:23 PM3/5/14
to django-...@googlegroups.com
#18668: Make related_query_name more configurable
-------------------------------------+-------------------------------------
Reporter: zmsmith | Owner: nobody
Type: New feature | Status: closed

Component: Database layer | Version: 1.4
(models, ORM) | Resolution: fixed

Severity: Normal | Triage Stage: Accepted
Keywords: | Needs documentation: 0
Has patch: 1 | Patch needs improvement: 1
Needs tests: 0 | UI/UX: 0
Easy pickings: 0 |
-------------------------------------+-------------------------------------
Changes (by loic84):

* status: new => closed
* resolution: => fixed


Comment:

#22207 [b77f26313cddbfde20dcf2661e9bd35458c2d1bd] fixed the remaining case
of generic relations.

--
Ticket URL: <https://code.djangoproject.com/ticket/18668#comment:4>

Reply all
Reply to author
Forward
0 new messages