~kkubasik/django/aggregation-branch

« back to all changes in this revision

Viewing changes to django/db/models/__init__.py

  • Committer: adrian
  • Date: 2006-05-02 01:31:56 UTC
  • Revision ID: vcs-imports@canonical.com-20060502013156-2941fcd40d080649
MERGED MAGIC-REMOVAL BRANCH TO TRUNK. This change is highly backwards-incompatible. Please read http://code.djangoproject.com/wiki/RemovingTheMagic for upgrade instructions.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
from django.conf import settings
 
2
from django.core.exceptions import ObjectDoesNotExist, ImproperlyConfigured
 
3
from django.core import validators
 
4
from django.db import backend, connection
 
5
from django.db.models.loading import get_apps, get_app, get_models, get_model, register_models
 
6
from django.db.models.query import Q
 
7
from django.db.models.manager import Manager
 
8
from django.db.models.base import Model, AdminOptions
 
9
from django.db.models.fields import *
 
10
from django.db.models.fields.related import ForeignKey, OneToOneField, ManyToManyField, ManyToOneRel, ManyToManyRel, OneToOneRel, TABULAR, STACKED
 
11
from django.db.models import signals
 
12
from django.utils.functional import curry
 
13
from django.utils.text import capfirst
 
14
 
 
15
# Admin stages.
 
16
ADD, CHANGE, BOTH = 1, 2, 3
 
17
 
 
18
class LazyDate:
 
19
    """
 
20
    Use in limit_choices_to to compare the field to dates calculated at run time
 
21
    instead of when the model is loaded.  For example::
 
22
 
 
23
        ... limit_choices_to = {'date__gt' : models.LazyDate(days=-3)} ...
 
24
 
 
25
    which will limit the choices to dates greater than three days ago.
 
26
    """
 
27
    def __init__(self, **kwargs):
 
28
        self.delta = datetime.timedelta(**kwargs)
 
29
 
 
30
    def __str__(self):
 
31
        return str(self.__get_value__())
 
32
 
 
33
    def __repr__(self):
 
34
        return "<LazyDate: %s>" % self.delta
 
35
 
 
36
    def __get_value__(self):
 
37
        return datetime.datetime.now() + self.delta
 
38
 
 
39
    def __getattr__(self, attr):
 
40
        return getattr(self.__get_value__(), attr)