diff --git a/persistent_messages/storage.py b/persistent_messages/storage.py index 67caf91..aac80c0 100644 --- a/persistent_messages/storage.py +++ b/persistent_messages/storage.py @@ -5,7 +5,12 @@ from django.contrib.auth.models import AnonymousUser from django.contrib.messages.storage.fallback import FallbackStorage from django.db.models import Q -import datetime + +try: + from django.utils.timezone import now # pre Django 1.4 +except ImportError: + from datetime import datetime # Django 1.4 + now = datetime.now def get_user(request): if hasattr(request, 'user') and request.user.__class__ != AnonymousUser: @@ -29,7 +34,7 @@ def __init__(self, *args, **kwargs): self.is_anonymous = not get_user(self.request).is_authenticated() def _message_queryset(self, exclude_unread=True): - qs = Message.objects.filter(user=get_user(self.request)).filter(Q(expires=None) | Q(expires__gt=datetime.datetime.now())) + qs = Message.objects.filter(user=get_user(self.request)).filter(Q(expires=None) | Q(expires__gt=now())) if exclude_unread: qs = qs.exclude(read=True) return qs