Calculated feild in models

42 views
Skip to first unread message

eankomah

unread,
Sep 19, 2020, 11:15:30 AM9/19/20
to Django users
I have two fields: 
    quantity = models.FloatField()
    unit_price = models.FloatField()

and i want ot do someting like this


    total_price = models.FloatField('unit_price' * 'quantity')

Thanks

coolguy

unread,
Sep 19, 2020, 2:56:36 PM9/19/20
to Django users
Create a function at class level like this..

class xxx(models.Model):
        quantity = models.FloatField()
        unit_price = models.FloatField()

        def get_total_price(self):
             return self.quantity * self.unit_price


Mohammad Ahshan Danish

unread,
Sep 19, 2020, 3:30:28 PM9/19/20
to django...@googlegroups.com
Create a model and add functions  if you want to go more deep use Model-manager.

--
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...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/daa1a5d0-1266-49fa-a453-ceaa5f7785fcn%40googlegroups.com.


--
Thanks & Regards 
  
Regards, 
Danish

Arpana Mehta

unread,
Sep 19, 2020, 5:33:12 PM9/19/20
to django...@googlegroups.com
You can use @property 

--
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...@googlegroups.com.

EA Media House

unread,
Sep 19, 2020, 8:13:08 PM9/19/20
to django...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages