Reputation: 43
app is runing good but when i try to add some items into add item through admin panel then I got this error meanwhile I have add product in my model.
error says: AttributeError at /admin/store/orderitem/add/ 'OrderItem' object has no attribute 'Product'
code of add item model:
class OrderItem(models.Model):
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)
def __str__(self):
return self.Product.name
Upvotes: 1
Views: 400
Reputation: 867
I think the problem is that you write Product
with a capital P in __str__
, while it has a lowercase p in the OrderItem
class
Upvotes: 1