Skip to content

Commit

Permalink
Handle timezone on 1.4 correctly.
Browse files Browse the repository at this point in the history
  • Loading branch information
jezdez committed May 7, 2012
1 parent f1e680a commit 2f27327
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions dbtemplates/models.py
@@ -1,6 +1,4 @@
# -*- coding: utf-8 -*-
from datetime import datetime

from django.db import models
from django.db.models import signals
from django.template import TemplateDoesNotExist
Expand All @@ -13,6 +11,12 @@
from dbtemplates.utils.cache import add_template_to_cache, remove_cached_template
from dbtemplates.utils.template import get_template_source

try:
from django.utils.timezone import now
except ImportError:
from datetime import datetime
now = datetime.now


class Template(models.Model):
"""
Expand All @@ -25,9 +29,9 @@ class Template(models.Model):
sites = models.ManyToManyField(Site, verbose_name=_(u'sites'),
blank=True, null=True)
creation_date = models.DateTimeField(_('creation date'),
default=datetime.now)
default=now)
last_changed = models.DateTimeField(_('last changed'),
default=datetime.now)
default=now)

objects = models.Manager()
on_site = CurrentSiteManager('sites')
Expand Down Expand Up @@ -56,7 +60,7 @@ def populate(self, name=None):
pass

def save(self, *args, **kwargs):
self.last_changed = datetime.now()
self.last_changed = now()
# If content is empty look for a template with the given name and
# populate the template instance with its content.
if settings.DBTEMPLATES_AUTO_POPULATE_CONTENT and not self.content:
Expand Down

0 comments on commit 2f27327

Please sign in to comment.