Ticket #3096: 3096-get_choices.diff

File 3096-get_choices.diff, 1.2 KB (added by Ivan Sagalaev <Maniac@…>, 16 years ago)

Patch using get_choices

  • django/contrib/admin/filterspecs.py

     
    6060            self.lookup_title = f.verbose_name
    6161        self.lookup_kwarg = '%s__%s__exact' % (f.name, f.rel.to._meta.pk.name)
    6262        self.lookup_val = request.GET.get(self.lookup_kwarg, None)
    63         self.lookup_choices = f.rel.to._default_manager.all()
     63        self.lookup_choices = f.get_choices(include_blank=False)
    6464
    6565    def has_output(self):
    6666        return len(self.lookup_choices) > 1
     
    7272        yield {'selected': self.lookup_val is None,
    7373               'query_string': cl.get_query_string({}, [self.lookup_kwarg]),
    7474               'display': _('All')}
    75         for val in self.lookup_choices:
    76             pk_val = getattr(val, self.field.rel.to._meta.pk.attname)
     75        for pk_val, val in self.lookup_choices:
    7776            yield {'selected': self.lookup_val == smart_unicode(pk_val),
    7877                   'query_string': cl.get_query_string({self.lookup_kwarg: pk_val}),
    7978                   'display': val}
Back to Top