﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
26230	RelatedField.related_query_name should default to _meta.default_related_name if defined.	Daniel Bate	Yi-Shan, Chen	"If I attach a `default_related_name` for my model using the name in a model lookup fails.

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`"	Bug	closed	Database layer (models, ORM)	dev	Normal	fixed			Accepted	1	0	0	1	0	0
