summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRussell Keith-Magee <russell@keith-magee.com>2007-04-09 13:28:09 +0000
committerRussell Keith-Magee <russell@keith-magee.com>2007-04-09 13:28:09 +0000
commitbbeb62c9af5939b92a18da31e2faafb726bc6b05 (patch)
treee3fc5b37759fabe366f4c244cd511655d992e1e8
parent17fac1b09bd693d9d113dfe4aac6b58743d59e76 (diff)
Backwards-incompatible change -- Removed LazyDate helper class. To preserve existing functionality, query arguments can now be callable. Callable query arguments are evaluated with the query is evaluated.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@4985 bcc190cf-cafb-0310-a4f2-bffc1f526a37
-rw-r--r--django/contrib/auth/models.py4
-rw-r--r--django/db/models/__init__.py29
-rw-r--r--django/db/models/query.py4
-rw-r--r--docs/model-api.txt6
4 files changed, 8 insertions, 35 deletions
diff --git a/django/contrib/auth/models.py b/django/contrib/auth/models.py
index 12c6a978b9..f686d90e7a 100644
--- a/django/contrib/auth/models.py
+++ b/django/contrib/auth/models.py
@@ -98,8 +98,8 @@ class User(models.Model):
is_staff = models.BooleanField(_('staff status'), default=False, help_text=_("Designates whether the user can log into this admin site."))
is_active = models.BooleanField(_('active'), default=True, help_text=_("Designates whether this user can log into the Django admin. Unselect this instead of deleting accounts."))
is_superuser = models.BooleanField(_('superuser status'), default=False, help_text=_("Designates that this user has all permissions without explicitly assigning them."))
- last_login = models.DateTimeField(_('last login'), default=models.LazyDate())
- date_joined = models.DateTimeField(_('date joined'), default=models.LazyDate())
+ last_login = models.DateTimeField(_('last login'), default=datetime.datetime.now)
+ date_joined = models.DateTimeField(_('date joined'), default=datetime.datetime.now)
groups = models.ManyToManyField(Group, verbose_name=_('groups'), blank=True,
help_text=_("In addition to the permissions manually assigned, this user will also get all permissions granted to each group he/she is in."))
user_permissions = models.ManyToManyField(Permission, verbose_name=_('user permissions'), blank=True, filter_interface=models.HORIZONTAL)
diff --git a/django/db/models/__init__.py b/django/db/models/__init__.py
index 13832f95a3..ccd60023f9 100644
--- a/django/db/models/__init__.py
+++ b/django/db/models/__init__.py
@@ -27,32 +27,3 @@ def permalink(func):
viewname = bits[0]
return reverse(bits[0], None, *bits[1:3])
return inner
-
-class LazyDate(object):
- """
- Use in limit_choices_to to compare the field to dates calculated at run time
- instead of when the model is loaded. For example::
-
- ... limit_choices_to = {'date__gt' : models.LazyDate(days=-3)} ...
-
- which will limit the choices to dates greater than three days ago.
- """
- def __init__(self, **kwargs):
- self.delta = datetime.timedelta(**kwargs)
-
- def __str__(self):
- return str(self.__get_value__())
-
- def __repr__(self):
- return "<LazyDate: %s>" % self.delta
-
- def __get_value__(self):
- return (datetime.datetime.now() + self.delta).date()
-
- def __getattr__(self, attr):
- if attr == 'delta':
- # To fix ticket #3377. Note that normal accesses to LazyDate.delta
- # (after construction) will still work, because they don't go
- # through __getattr__). This is mainly needed for unpickling.
- raise AttributeError
- return getattr(self.__get_value__(), attr)
diff --git a/django/db/models/query.py b/django/db/models/query.py
index e01905551e..a0032592a8 100644
--- a/django/db/models/query.py
+++ b/django/db/models/query.py
@@ -826,7 +826,9 @@ def parse_lookup(kwarg_items, opts):
# Interpret '__exact=None' as the sql '= NULL'; otherwise, reject
# all uses of None as a query value.
if lookup_type != 'exact':
- raise ValueError, "Cannot use None as a query value"
+ raise ValueError, "Cannot use None as a query value"
+ elif callable(value):
+ value = value()
joins2, where2, params2 = lookup_inner(path, lookup_type, value, opts, opts.db_table, None)
joins.update(joins2)
diff --git a/docs/model-api.txt b/docs/model-api.txt
index a03ed09eb2..400617a012 100644
--- a/docs/model-api.txt
+++ b/docs/model-api.txt
@@ -734,10 +734,10 @@ relationship should work. All are optional:
``limit_choices_to`` A dictionary of lookup arguments and values (see
the `Database API reference`_) that limit the
available admin choices for this object. Use this
- with ``models.LazyDate`` to limit choices of objects
- by date. For example::
+ with functions from the Python ``datetime`` module
+ to limit choices of objects by date. For example::
- limit_choices_to = {'pub_date__lte': models.LazyDate()}
+ limit_choices_to = {'pub_date__lte': datetime.now}
only allows the choice of related objects with a
``pub_date`` before the current date/time to be