I have a model called OrderItem
class OrderItem(models.Model):
customer = models.ForeignKey(
User, on_delete=models.SET_NULL, blank=True, null=True)
product = models.ForeignKey(
Product, on_delete=models.SET_NULL, blank=True, null=True)
order = models.ForeignKey(
Order, on_delete=models.SET_NULL, blank=True, null=True)
quantity = models.IntegerField(default=0, null=True, blank=True)
date_added = models.DateTimeField(auto_now_add=True)
and a model called Order
class Order(models.Model):
customer = models.ForeignKey(
User, on_delete=models.SET_NULL, blank=True, null=True)
date_ordered = models.DateTimeField(auto_now_add=True)
complete = models.BooleanField(default=False, null=True, blank=False)
transaction_id = models.CharField(max_length=200, null=True)
Now in my views.py
I have an OrderItem model order
instance. And in my Order model I need to set its order
instance to complete. I'm trying something as follows:
orderID = OrderItem.objects.filter(order_id=4)
#lets say there are more than one order_id with the value of 4
for order in orderID:
order = Order.objects.get(id=orderID)
order.complete=True
order.save()
this code gives me:
ValueError: The QuerySet value for an exact lookup must be limited to one result using slicing.
How to fix this?