Saturday, September 19, 2020

Re: Calculated feild in models

Create a model and add functions  if you want to go more deep use Model-manager.

On Sun, Sep 20, 2020 at 12:27 AM coolguy <cooldjangoprogrammer@gmail.com> wrote:
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


On Saturday, September 19, 2020 at 11:15:30 AM UTC-4 eankomah wrote:
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

--
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+unsubscribe@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

--
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+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAPQdaF31VwATcG%2BgNGz9zEK84ftsJ3BD9o2CnbJi7E9%2BEH22OA%40mail.gmail.com.

No comments:

Post a Comment