Commits

Ian George  committed c74959f

Tidying up session create code

  • Participants
  • Parent commits f8cef09

Comments (0)

Files changed (1)

File quiet/shop/session.py

             self.basket_id = request.session.get(BASKET_SESSION_KEY)
         except:
             self.basket_id = int(request)
-        basket, created = Basket.objects.get_or_create(id=self.basket_id)
+
+        created = False
+        try:
+            basket = Basket.objects.get(id=self.basket_id)
+        except Basket.DoesNotExist:
+            basket = Basket()
+            basket.save()
+            created = True
+
         if created and request and hasattr(request, 'session'):
             request.session[BASKET_SESSION_KEY] = basket.id
         self.basket = basket