python - How to store django objects as session variables ( object is not JSON serializable)? -


i have simple view

def foo(request):    card = card.objects.latest(datetime)    request.session['card']=card 

for above code error

"<card: card object> not json serializable" 

django version 1.6.2. doing wrong ?

in cookie, i'd store object primary key:

request.session['card'] = card.id 

and when loading card session, obtain card again with:

try:     card = card.objects.get(id=request.session['card']) except (keyerror, card.doesnotexist):     card = none 

which set card none if there isn't card entry in session or specific card doesn't exist.


Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -