django 1.4 only creates session if needed
This commit is contained in:
parent
bece439d62
commit
99aee48d98
1 changed files with 4 additions and 0 deletions
|
@ -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)
|
||||||
|
|
Loading…
Reference in a new issue