#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 <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 django-updates@googlegroups.com.
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to