For example, if I have the following models:
{{{
from django.db import models
class Foo(models.Model):
a = models.IntegerField(default=0)
class Bar(models.Model):
foo = models.ForeignKey(Foo, related_name='bars')
class Boo(models.Model):
foo = models.ForeignKey(Foo)
class Meta:
default_related_name = 'boos'
}}}
And the following tests:
{{{
from django.test import TestCase
from .models import Foo, Bar, Boo
class Test(TestCase):
def setUp(self):
self.foo = Foo.objects.create()
def test_related_name_on_field___all_is_fine(self):
instance = Bar.objects.create(foo=self.foo)
# get related set
self.assertEqual(instance, self.foo.bars.first())
# filter foos through lookup
self.assertEqual(self.foo, Foo.objects.get(bars=instance))
def test_related_name_is_default___lookup_fails(self):
instance = Boo.objects.create(foo=self.foo)
# get related set
self.assertEqual(instance, self.foo.boos.first())
# filter foos through lookup
self.assertEqual(self.foo, Foo.objects.get(boos=instance))
}}}
I get the following error:
{{{
django.core.exceptions.FieldError: Cannot resolve keyword 'boos' into
field. Choices are: a, bars, boo, id
}}}
This shows I can use `boos` as a property for `Foo` objects but when i try
to use it in a lookup it is expecting `boo` rather than `boos`
--
Ticket URL: <https://code.djangoproject.com/ticket/26230>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* needs_better_patch: => 0
* component: Uncategorized => Database layer (models, ORM)
* needs_tests: => 0
* version: 1.9 => master
* needs_docs: => 0
* type: Uncategorized => Bug
* stage: Unreviewed => Accepted
Comment:
This was also brought up on [https://groups.google.com/d/msg/django-
users/OGavpqJrw6g/H09wAh35CAAJ django-users] a couple of months ago.
--
Ticket URL: <https://code.djangoproject.com/ticket/26230#comment:1>
--
Ticket URL: <https://code.djangoproject.com/ticket/26230#comment:2>
* owner: nobody => chenesan
* status: new => assigned
Comment:
I'll work on this in the next few days.
--
Ticket URL: <https://code.djangoproject.com/ticket/26230#comment:3>
* has_patch: 0 => 1
Comment:
PR https://github.com/django/django/pull/6187
--
Ticket URL: <https://code.djangoproject.com/ticket/26230#comment:4>
* needs_better_patch: 0 => 1
Comment:
The pull request is backwards-incompatible. It would be nice to have a
deprecation path if possible.
--
Ticket URL: <https://code.djangoproject.com/ticket/26230#comment:5>
* status: assigned => closed
* resolution: => fixed
Comment:
In [changeset:"b84f5ab4ec2d1edbe9a7effa9f75a3caa189bace" b84f5ab4]:
{{{
#!CommitTicketReference repository=""
revision="b84f5ab4ec2d1edbe9a7effa9f75a3caa189bace"
Fixed #26230 -- Made default_related_name affect related_query_name.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/26230#comment:6>
Comment (by Tim Graham <timograham@…>):
In [changeset:"bfe0d54514bf4f03bc4a956452541f0103134ba3" bfe0d54]:
{{{
#!CommitTicketReference repository=""
revision="bfe0d54514bf4f03bc4a956452541f0103134ba3"
Refs #26230 -- Removed support for model name query lookups when using
Meta.default_related_name.
Per deprecation timeline.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/26230#comment:7>