title: TypeError: Object of type Cart is not JSON serializable
body: <p>I just started using session in Django framework. I have create an object cart from Cart model. And when i wan to set cart inside request.session with session['cart'] = cart, I get this error message: TypeError: Object of type Cart is not JSON serializable</p>
  
  <p>This is my Cart model</p>
  
  <pre class="lang-py prettyprint-override"><code>class Cart(object):
  
      def __init__(self):
          self.items = []
  
      def addItem(self, itemCart):
          try:
              # get index of itemCart if exist
              index = self.items.index(itemCart)
              # itemCart exist then set its quantity
              self.items[index].setQuantity(
                  self.items[index].quantity + itemCart.quantity)
          except ValueError:
              # the item does not exits then add to items list
              self.items.append(itemCart)
  </code></pre>
  
  <p>This is my view when i update the session</p>
  
  <pre class="lang-py prettyprint-override"><code>cart = Cart()
  session['cart'] = cart
  </code></pre>
  
  <p>And When i run the code i get this error:
   File "C:\Users\Patrick-PC\AppData\Local\Programs\Python\Python37\lib\json\encoder.py", line 179, in default
      raise TypeError(f'Object of type {o.<strong>class</strong>.<strong>name</strong>} '
  TypeError: Object of type Cart is not JSON serializable.</p>
  
  <p>Please help</p>