Query for ForeignKey using implicit exact and to_field breaks
|Reported by:||Jeremy Dunck||Owned by:||nobody|
|Component:||Database layer (models, ORM)||Version:||master|
|Has patch:||no||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
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() 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.