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. --- tests/admin_views/models.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'tests/admin_views/models.py') 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', ( -- cgit v1.3