tanks for this, it was helpfull

On Thu, 13 May 2021 at 15:31, Ryan Nowakowski <[email protected]> wrote:

> It's likely that your instance of OrderItem has a product field that's
> null.
>
> On May 12, 2021 3:50:42 AM CDT, Peter Kirieny <[email protected]>
> wrote:
> >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/FDF6B1C2-9134-43D2-8057-EA3BCF14C2A1%40fattuba.com
> .
>

-- 
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/CAL8t8eoTHsQh2Lu6oVWdF8sZvoBgTMTrEY4KFU__eepU0QP1uw%40mail.gmail.com.

Reply via email to