django 1.4 only creates session if needed

This commit is contained in:
j 2012-05-24 14:39:41 +00:00
parent bece439d62
commit 99aee48d98

View file

@ -89,7 +89,11 @@ class SessionData(models.Model):
@classmethod @classmethod
def get_or_create(cls, request): def get_or_create(cls, request):
if not request.session.session_key:
request.session.save()
request.session.modified = True
session_key = request.session.session_key session_key = request.session.session_key
assert session_key
if request.user.is_authenticated(): if request.user.is_authenticated():
cls.objects.filter(user=request.user).update(session_key=session_key) cls.objects.filter(user=request.user).update(session_key=session_key)
data, created = cls.objects.get_or_create(session_key=session_key) data, created = cls.objects.get_or_create(session_key=session_key)