Donald Stufft avatar Donald Stufft committed 6dbdb35

updated to use the new 1.4 timezones

Comments (0)

Files changed (2)

model_utils/fields.py

 
 from model_utils import Choices
 
+
+try:
+    from django.utils.timezone import now as now
+except ImportError:
+    now = datetime.now
+
+
 class AutoCreatedField(models.DateTimeField):
     """
     A DateTimeField that automatically populates itself at
     """
     def __init__(self, *args, **kwargs):
         kwargs.setdefault('editable', False)
-        kwargs.setdefault('default', datetime.now)
+        kwargs.setdefault('default', now)
         super(AutoCreatedField, self).__init__(*args, **kwargs)
 
 
 
     """
     def pre_save(self, model_instance, add):
-        value = datetime.now()
+        value = now()
         setattr(model_instance, self.attname, value)
         return value
 
 
     """
     def __init__(self, *args, **kwargs):
-        kwargs.setdefault('default', datetime.now)
+        kwargs.setdefault('default', now)
         monitor = kwargs.pop('monitor', None)
         if not monitor:
             raise TypeError(
                 self.get_monitored_value(instance))
 
     def pre_save(self, model_instance, add):
-        value = datetime.now()
+        value = now()
         previous = getattr(model_instance, self.monitor_attname, None)
         current = self.get_monitored_value(model_instance)
         if previous != current:

model_utils/models.py

 from model_utils.fields import AutoCreatedField, AutoLastModifiedField, \
     StatusField, MonitorField
 
+try:
+    from django.utils.timezone import now as now
+except ImportError:
+    now = datetime.now
+
+
 class InheritanceCastModel(models.Model):
     """
     An abstract base class that provides a ``real_type`` FK to ContentType.
         sender._meta.get_field('timeframed')
         raise ImproperlyConfigured("Model '%s' has a field named "
                                    "'timeframed' which conflicts with "
-                                   "the TimeFramedModel manager." 
+                                   "the TimeFramedModel manager."
                                    % sender.__name__)
     except FieldDoesNotExist:
         pass
     sender.add_to_class('timeframed', QueryManager(
-        (models.Q(start__lte=datetime.now) | models.Q(start__isnull=True)) &
-        (models.Q(end__gte=datetime.now) | models.Q(end__isnull=True))
+        (models.Q(start__lte=now) | models.Q(start__isnull=True)) &
+        (models.Q(end__gte=now) | models.Q(end__isnull=True))
     ))
 
 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.