Django

Code

Changeset 4985

Show
Ignore:
Timestamp:
04/09/07 08:28:09 (1 year ago)
Author:
russellm
Message:

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.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/trunk/django/contrib/auth/models.py

    r4945 r4985  
    9999    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.")) 
    100100    is_superuser = models.BooleanField(_('superuser status'), default=False, help_text=_("Designates that this user has all permissions without explicitly assigning them.")) 
    101     last_login = models.DateTimeField(_('last login'), default=models.LazyDate()
    102     date_joined = models.DateTimeField(_('date joined'), default=models.LazyDate()
     101    last_login = models.DateTimeField(_('last login'), default=datetime.datetime.now
     102    date_joined = models.DateTimeField(_('date joined'), default=datetime.datetime.now
    103103    groups = models.ManyToManyField(Group, verbose_name=_('groups'), blank=True, 
    104104        help_text=_("In addition to the permissions manually assigned, this user will also get all permissions granted to each group he/she is in.")) 
  • django/trunk/django/db/models/__init__.py

    r4498 r4985  
    2828        return reverse(bits[0], None, *bits[1:3]) 
    2929    return inner 
    30  
    31 class LazyDate(object): 
    32     """ 
    33     Use in limit_choices_to to compare the field to dates calculated at run time 
    34     instead of when the model is loaded.  For example:: 
    35  
    36         ... limit_choices_to = {'date__gt' : models.LazyDate(days=-3)} ... 
    37  
    38     which will limit the choices to dates greater than three days ago. 
    39     """ 
    40     def __init__(self, **kwargs): 
    41         self.delta = datetime.timedelta(**kwargs) 
    42  
    43     def __str__(self): 
    44         return str(self.__get_value__()) 
    45  
    46     def __repr__(self): 
    47         return "<LazyDate: %s>" % self.delta 
    48  
    49     def __get_value__(self): 
    50         return (datetime.datetime.now() + self.delta).date() 
    51  
    52     def __getattr__(self, attr): 
    53         if attr == 'delta': 
    54             # To fix ticket #3377. Note that normal accesses to LazyDate.delta 
    55             # (after construction) will still work, because they don't go 
    56             # through __getattr__). This is mainly needed for unpickling. 
    57             raise AttributeError 
    58         return getattr(self.__get_value__(), attr) 
  • django/trunk/django/db/models/query.py

    r4772 r4985  
    827827            # all uses of None as a query value. 
    828828            if lookup_type != 'exact': 
    829                 raise ValueError, "Cannot use None as a query value" 
     829                raise ValueError, "Cannot use None as a query value"       
     830        elif callable(value): 
     831            value = value() 
    830832 
    831833        joins2, where2, params2 = lookup_inner(path, lookup_type, value, opts, opts.db_table, None) 
  • django/trunk/docs/model-api.txt

    r4891 r4985  
    735735                             the `Database API reference`_) that limit the 
    736736                             available admin choices for this object. Use this 
    737                              with ``models.LazyDate`` to limit choices of objects 
    738                              by date. For example:: 
    739  
    740                                 limit_choices_to = {'pub_date__lte': models.LazyDate()
     737                             with functions from the Python ``datetime`` module  
     738                             to limit choices of objects by date. For example:: 
     739 
     740                                limit_choices_to = {'pub_date__lte': datetime.now
    741741 
    742742                             only allows the choice of related objects with a