Ticket #1592: related_with_limit_choices.diff

File related_with_limit_choices.diff, 578 bytes (added by mir@…, 19 years ago)

patch

  • django/db/models/fields/related.py

    a b class ReverseSingleRelatedObjectDescript  
    132132                params = {'%s__pk' % self.field.rel.field_name: val}
    133133            else:
    134134                params = {'%s__exact' % self.field.rel.field_name: val}
     135                if self.field.rel.limit_choices_to:
     136                    params.update(self.field.rel.limit_choices_to)
    135137            rel_obj = self.field.rel.to._default_manager.get(**params)
    136138            setattr(instance, cache_name, rel_obj)
    137139            return rel_obj
Back to Top