From eefc88feefec0c3685bfb102714530b751b4ae90 Mon Sep 17 00:00:00 2001 From: Christopher Adams Date: Sat, 1 Feb 2014 14:23:31 -0500 Subject: Fixed #2445 -- Allowed limit_choices_to attribute to be a callable. ForeignKey or ManyToManyField attribute ``limit_choices_to`` can now be a callable that returns either a ``Q`` object or a dict. Thanks michael at actrix.gen.nz for the original suggestion. --- django/forms/fields.py | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'django/forms/fields.py') diff --git a/django/forms/fields.py b/django/forms/fields.py index 1ce36c199c..629aa69c5d 100644 --- a/django/forms/fields.py +++ b/django/forms/fields.py @@ -170,6 +170,17 @@ class Field(object): """ return {} + def get_limit_choices_to(self): + """ + Returns ``limit_choices_to`` for this form field. + + If it is a callable, it will be invoked and the result will be + returned. + """ + if callable(self.limit_choices_to): + return self.limit_choices_to() + return self.limit_choices_to + def _has_changed(self, initial, data): """ Return True if data differs from initial. -- cgit v1.3