switch from naive timestamps to timezone-aware timestamps
diff --git a/planetstack/core/models/billing.py b/planetstack/core/models/billing.py
index 6d1c331..8c61418 100644
--- a/planetstack/core/models/billing.py
+++ b/planetstack/core/models/billing.py
@@ -6,6 +6,7 @@
from django.contrib.contenttypes.models import ContentType
from django.contrib.contenttypes import generic
from django.db.models import Sum
+from django.utils import timezone
class Account(PlCoreBase):
site = models.ForeignKey(Site, related_name="accounts", help_text="Site for this account")
@@ -51,7 +52,7 @@
class Payment(PlCoreBase):
account = models.ForeignKey(Account, related_name="payments")
amount = models.FloatField(default=0.0)
- date = models.DateTimeField(default=datetime.datetime.now)
+ date = models.DateTimeField(default=timezone.now)
def __unicode__(self): return u'%s-%0.2f-%s' % (self.account.site.name, self.amount, str(self.date))
diff --git a/planetstack/core/models/plcorebase.py b/planetstack/core/models/plcorebase.py
index d1784cd..d461c9d 100644
--- a/planetstack/core/models/plcorebase.py
+++ b/planetstack/core/models/plcorebase.py
@@ -1,10 +1,10 @@
-import datetime
import os
import sys
from django.db import models
from django.forms.models import model_to_dict
from django.core.urlresolvers import reverse
from django.forms.models import model_to_dict
+from django.utils import timezone
import model_policy
try:
@@ -23,9 +23,13 @@
# the core model is abstract.
class PlCoreBaseDeletionManager(models.Manager):
def get_queryset(self):
- return super(PlCoreBaseDeletionManager, self).get_query_set().filter(deleted=True)
+ parent=super(PlCoreBaseDeletionManager, self)
+ if hasattr(parent, "get_queryset"):
+ return parent.get_queryset().filter(deleted=True)
+ else:
+ return parent.get_query_set().filter(deleted=True)
- # deprecated in django 1.7 in favor of get_queryset()
+ # deprecated in django 1.7 in favor of get_queryset().
def get_query_set(self):
return self.get_queryset()
@@ -33,9 +37,13 @@
# the core model is abstract.
class PlCoreBaseManager(models.Manager):
def get_queryset(self):
- return super(PlCoreBaseManager, self).get_query_set().filter(deleted=False)
+ parent=super(PlCoreBaseManager, self)
+ if hasattr(parent, "get_queryset"):
+ return parent.get_queryset().filter(deleted=False)
+ else:
+ return parent.get_query_set().filter(deleted=False)
- # deprecated in django 1.7 in favor of get_queryset()
+ # deprecated in django 1.7 in favor of get_queryset().
def get_query_set(self):
return self.get_queryset()
@@ -45,8 +53,8 @@
# default values for created and updated are only there to keep evolution
# from failing.
- created = models.DateTimeField(auto_now_add=True, default=datetime.datetime.now)
- updated = models.DateTimeField(auto_now=True, default=datetime.datetime.now)
+ created = models.DateTimeField(auto_now_add=True, default=timezone.now)
+ updated = models.DateTimeField(auto_now=True, default=timezone.now)
enacted = models.DateTimeField(null=True, default=None)
backend_status = models.CharField(max_length=140,
default="Provisioning in progress")