hi there you can create another method for that class that calculates the
total as


@property
def get_total_price(self):
     total_price = self.unit_price * self.quantity
     return total_price


On Wed, Sep 23, 2020 at 8:24 AM eankomah <csceanko...@gmail.com> wrote:

> Hi all am stuck at getting total_price Calculated in my model
>
> class inventory(models.Model):
>     def __str__(self):
>         return self.name
>
>
>     category = models.ForeignKey(Category, null=True, on_delete = 
> models.SET_NULL)
>
>     Supplier = models.ForeignKey(Supplier, null=True, on_delete = 
> models.SET_NULL)
>
>     product = models.ForeignKey(Product, null=True, on_delete = 
> models.SET_NULL)
>     quantity = models.FloatField()
>     unit_price = models.FloatField()
>     total_price = models.FloatField(total=('unit_price' * 'quantity'))
>     selling_price = models.FloatField()
>     date_created = models.DateTimeField(auto_now_add=True)
>
>
> Thanks
>
> --
> 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 django-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/4ab25477-99fa-4de4-a774-667d336235e6n%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/4ab25477-99fa-4de4-a774-667d336235e6n%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>

-- 
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 django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAJofND7nGPRtn6hOHCwQAudVA-JzDGb0p-VWE8Yhoyp22rjq2A%40mail.gmail.com.

Reply via email to