﻿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
4957	Query for ForeignKey using implicit exact and to_field breaks	Jeremy Dunck	nobody	"Given these models:
{{{
class District(models.Model, models.GeoMixin):
    tea_number = models.CharField(maxlength=20, unique=True)

class School(models.Model, models.GeoMixin):
    district = models.ForeignKey(District, to_field='tea_number')
}}}

I expect this to work:
{{{
a_district = District.objects.all()[0]
Schools.objects.filter(district=a_district)
}}}
So that a_district's tea_nuumber attribute is used for the criteria against the School table rather than the District's PK.

django.db.models.query.lookup_inner (line 1082) has the bug:
{{{
                # RelatedObject is from a 1-1 relation,
                # No need to join; get the pk value from the related object,
                # and compare using that.
                column = current_opts.pk.name
}}}

I'll try to work up a patch for it.  Tired now."		closed	Database layer (models, ORM)	dev		duplicate	qs-rf-fixed		Accepted	0	0	0	0	0	0
