﻿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
2269	limit_choices_to should use to_field	mir@…	Adrian Holovaty	"When I do something like this:

{{{
class Blupp(models.Model):
  kind = IntegerField()
  another_key=IntegerField()

class Blipp(models.Model):
  wont_work = ForeignKey(Blupp, limit_choices_to({'kind__exact': 1}), to_field='another_key')
}}}

Then the choices for Blipp will be computed to the primary key of Blupp, no to ``another_key``

I blame ``Field.get_choices()``, here's the code:

{{{
    def get_choices(self, include_blank=True, blank_choice=BLANK_CHOICE_DASH):
        ""Returns a list of tuples used as SelectField choices for this field.""
        first_choice = include_blank and blank_choice or []
        if self.choices:
            return first_choice + list(self.choices)
        rel_model = self.rel.to
        return first_choice + [(x._get_pk_val(), str(x))
                               for x in rel_model._default_manager.complex_filter(self.rel.limit_choices_to)]
}}}

In the second last line, x._get_pk_val() needs to be replaced.
"	defect	closed	Core (Other)	dev	normal	fixed			Unreviewed	0	0	0	0	0	0
