can somebody help with this please, am building an ecommerce web and when i want to view my cart i get this error
AttributeError: 'NoneType' object has no attribute 'price'
here is my models.py
class OrderItem(models.Model):
product = models.ForeignKey(Product, on_delete=models.SET_NULL, null=True)
order = models.ForeignKey(Order, on_delete=models.SET_NULL, null=True)
quantity = models.IntegerField(default=0, null=True, blank=True)
date_added = models.DateTimeField(auto_now_add=True)
@property
def get_total(self):
total = self.product.price * self.quantity
return total
AttributeError at /cart/
'NoneType' object has no attribute 'price'
Request Method: | GET |
---|
Request URL: | http://127.0.0.1:8000/cart/ |
---|
Django Version: | 3.2 |
---|
Exception Type: | AttributeError |
---|
Exception Value: | 'NoneType' object has no attribute 'price' |
---|
Exception Location: | C:\Users\Admin\PycharmProject\MyProject\Ecommerce\shop\models.py, line 71, in get_total |
---|
Python Executable: | C:\Users\Admin\PycharmProject\MyProject\venv\Scripts\python.exe |
---|
Python Version: | 3.8.2 |
---|
Python Path: | ['C:\\Users\\Admin\\PycharmProject\\MyProject\\Ecommerce',
'C:\\Users\\Admin\\AppData\\Local\\Programs\\Python\\Python38\\python38.zip',
'C:\\Users\\Admin\\AppData\\Local\\Programs\\Python\\Python38\\DLLs',
'C:\\Users\\Admin\\AppData\\Local\\Programs\\Python\\Python38\\lib',
'C:\\Users\\Admin\\AppData\\Local\\Programs\\Python\\Python38',
'C:\\Users\\Admin\\PycharmProject\\MyProject\\venv',
'C:\\Users\\Admin\\PycharmProject\\MyProject\\venv\\lib\\site-packages'] |
---|
Server time: | Wed, 12 May 2021 08:44:09 +0000 |
---|