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
--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-users/CAL8t8eqL%3Dq6qMeBnk2Nq_TO%3D%3DivFvpuYuCR%3DkgtXv2H%3DHCkaQg%40mail.gmail.com.