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

前端 未结 6 1261
独厮守ぢ
独厮守ぢ 2021-02-13 17:58

I have a simple view

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

For the above code I get the

6条回答
  •  天涯浪人
    2021-02-13 18:14

    There are two simple ways to do this.

    • If each object belongs to a single session at the same time, store session id as a model field, and update models.
    • If an object can belong to multiple sessions at the same time, store object.id as a session variable.

提交回复
热议问题