summaryrefslogtreecommitdiff
path: root/tests/admin_views/models.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 /tests/admin_views/models.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 'tests/admin_views/models.py')
-rw-r--r--tests/admin_views/models.py27
1 files changed, 27 insertions, 0 deletions
diff --git a/tests/admin_views/models.py b/tests/admin_views/models.py
index ac4d4f20c5..4cc58f5e88 100644
--- a/tests/admin_views/models.py
+++ b/tests/admin_views/models.py
@@ -173,6 +173,33 @@ class Sketch(models.Model):
return self.title
+def today_callable_dict():
+ return {"last_action__gte": datetime.datetime.today()}
+
+
+def today_callable_q():
+ return models.Q(last_action__gte=datetime.datetime.today())
+
+
+@python_2_unicode_compatible
+class Character(models.Model):
+ username = models.CharField(max_length=100)
+ last_action = models.DateTimeField()
+
+ def __str__(self):
+ return self.username
+
+
+@python_2_unicode_compatible
+class StumpJoke(models.Model):
+ variation = models.CharField(max_length=100)
+ most_recently_fooled = models.ForeignKey(Character, limit_choices_to=today_callable_dict, related_name="+")
+ has_fooled_today = models.ManyToManyField(Character, limit_choices_to=today_callable_q, related_name="+")
+
+ def __str__(self):
+ return self.variation
+
+
class Fabric(models.Model):
NG_CHOICES = (
('Textured', (