Commit c17e3265 authored by Malcolm Tredinnick's avatar Malcolm Tredinnick
Browse files

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
parent 49316396
Loading
Loading
Loading
Loading
+13 −11
Original line number Diff line number Diff line
@@ -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
+6 −2
Original line number Diff line number Diff line
@@ -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>]