summaryrefslogtreecommitdiff
path: root/django/contrib/admin/widgets.py
diff options
context:
space:
mode:
authorChristopher Adams <christopher.r.adams@gmail.com>2014-02-01 14:23:31 -0500
committerTim Graham <timograham@gmail.com>2014-02-11 14:05:12 -0500
commiteefc88feefec0c3685bfb102714530b751b4ae90 (patch)
tree3cab4b02c13b76b6355d475d91ca2e157a126b18 /django/contrib/admin/widgets.py
parenta718fcf201b04ba254e9073be82f51ae1ae3a853 (diff)
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.
Diffstat (limited to 'django/contrib/admin/widgets.py')
-rw-r--r--django/contrib/admin/widgets.py5
1 files changed, 4 insertions, 1 deletions
diff --git a/django/contrib/admin/widgets.py b/django/contrib/admin/widgets.py
index f527d72f3f..f501ffb1a8 100644
--- a/django/contrib/admin/widgets.py
+++ b/django/contrib/admin/widgets.py
@@ -180,7 +180,10 @@ class ForeignKeyRawIdWidget(forms.TextInput):
return mark_safe(''.join(output))
def base_url_parameters(self):
- return url_params_from_lookup_dict(self.rel.limit_choices_to)
+ limit_choices_to = self.rel.limit_choices_to
+ if callable(limit_choices_to):
+ limit_choices_to = limit_choices_to()
+ return url_params_from_lookup_dict(limit_choices_to)
def url_parameters(self):
from django.contrib.admin.views.main import TO_FIELD_VAR