Fixed #7378 -- Use the "to_field" where appropriate on reverse relations.
Patch from mturtle@gmail.com. The remaining uses of "%s__pk" in fields/related.py all look safe, since they are for many-to-many fields, which doesn't take "to_field" as a parameter. git-svn-id: http://code.djangoproject.com/svn/django/trunk@7785 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
4931639636
commit
c17e326585
|
@ -322,7 +322,9 @@ class ForeignRelatedObjectsDescriptor(object):
|
|||
clear.alters_data = True
|
||||
|
||||
manager = RelatedManager()
|
||||
manager.core_filters = {'%s__pk' % rel_field.name: getattr(instance, rel_field.rel.get_related_field().attname)}
|
||||
attname = rel_field.rel.get_related_field().name
|
||||
manager.core_filters = {'%s__%s' % (rel_field.name, attname):
|
||||
getattr(instance, attname)}
|
||||
manager.model = self.related.model
|
||||
|
||||
return manager
|
||||
|
|
|
@ -368,6 +368,10 @@ Bug #4510
|
|||
>>> Author.objects.filter(report__name='r1')
|
||||
[<Author: a1>]
|
||||
|
||||
Bug #7378
|
||||
>>> a1.report_set.all()
|
||||
[<Report: r1>]
|
||||
|
||||
Bug #5324, #6704
|
||||
>>> Item.objects.filter(tags__name='t4')
|
||||
[<Item: four>]
|
||||
|
@ -777,8 +781,8 @@ this doesn't crash, it's a Good Thing.
|
|||
>>> out = pickle.dumps(Item.objects.all())
|
||||
|
||||
Bug #7277
|
||||
>>> a1 = Annotation.objects.create(name='a1', tag=t1)
|
||||
>>> a1.notes.add(n1)
|
||||
>>> ann1 = Annotation.objects.create(name='a1', tag=t1)
|
||||
>>> ann1.notes.add(n1)
|
||||
>>> n1.annotation_set.filter(Q(tag=t5) | Q(tag__children=t5) | Q(tag__children__children=t5))
|
||||
[<Annotation: a1>]
|
||||
|
||||
|
|
Loading…
Reference in New Issue