title: Please is there a way I can solve this error I think everything is well with this
body: <p>I have suffered from this error, please help me.<a href="https://i.stack.imgur.com/3k8Xk.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/3k8Xk.png" alt="is an error" /></a></p>
  <p>this is my views.py and models.py file please I need to create add to cart function, and this error one happens when I click the add to cart button using get_or_create function.
  here is the code:</p>
  <pre><code>def add_to_cart(request, slug):
      item = get_object_or_404(Item, slug=slug)
      order_item = OrderItem.objects.get_or_create(
          item=item,
          user=request.user,
          ordered=False
      )
      order_qs = Order.objects.filter(user=request.user, ordered=False)
      if order_qs.exists():
          order = order_qs[0]
          # check if the order is in the order
          if order.items.filter(item__slug=item.slug).exists():
              order_item.quantity += 1
              order_item.save()
          else:
              order.items.add(order_item)
      else:
          ordered_date = timezone.now()
          order = Order.objects.create(
              user=request.user, ordered_date=ordered_date)
          order.items.add(order_item)
      return redirect(&quot;core:product&quot;, slug=slug)
  
  class OrderItem(models.Model):
      user = models.ForeignKey(settings.AUTH_USER_MODEL, 
                               on_delete=models.CASCADE)
      ordered = models.BooleanField(default=False)
      item = models.ForeignKey(Item, on_delete=models.CASCADE)
      quantity = models.IntegerField(default=1)
  
      def __str__(self):
          return f&quot;{self.quantity} of {self.item.title}&quot;
  
  
  class Order(models.Model):
      user = models.ForeignKey(settings.AUTH_USER_MODEL, 
                               on_delete=models.CASCADE)
      items = models.ManyToManyField(OrderItem)
      start_date = models.DateTimeField(auto_now_add=True)
      ordered_date = models.DateTimeField()
      ordered = models.BooleanField(default=False)
  </code></pre>