'i want to add value to a field by calculating two values for tow fields in django api rest framework not template
#models file
I want to add value to deserved_amount field by calculating a payments minus from the class product inside field selling_price ... If there are any modifications to the important classes, I want to deduct a payment from the original amount and then show the remaining amount after each payment to the user... I want the process to rest framework api endpoint
# this class adds payment to each product price
class Payment(models.Model):
PK = models.AutoField(primary_key=True)
payments = models.FloatField(default=0)
description_paid = models.TextField(max_length=1500,
default='')
payment_date = models.DateField(default=datetime.date.today)
product =
models.ForeignKey('Product',related_name='paymentProducts' ,
on_delete=models.CASCADE)
imag_file = models.ImageField(upload_to='uploads' , blank=True ,
null=True)
deserved_amount = models.FloatField(default=0, null=True ,
blank=True)
'''
I want to add value to deserved_amount field by calculating a
payments minus from
the class product inside field selling_price ...
please help me , thanks
'''
#this is class add a product this is class add a product this is
#class add a product this is class add a product this is class add
#**strong text**product
class Product(models.Model):
JAWWAL = 'JAWWAL'
type_category = [
(JAWWAL,'جوال'),
('SCREEN','شاشة'),
('FRIDGE','ثلاجة'),
('LAPTOP','لابتوب'),
('WASHER','غسالة'),
('ELECTRICAL DEVICES','جهاز كهربائي'),
('FURNITURE','موبيليا'),
('ATHER','اخرى'),
]
PK = models.AutoField(primary_key=True)
cost_price = models.FloatField(default=0)
selling_price = models.FloatField(default=0)
supplier_name = models.CharField(max_length=70 , blank=True ,
null=True)
category = models.CharField(max_length=19,
choices=type_category,default=JAWWAL)
description = models.TextField(max_length=1500, default='')
date = models.DateTimeField(auto_now_add=True ,
blank=True , null=True )
customer = models.ForeignKey('customer',
related_name='customerProducts', on_delete=models.CASCADE)
payment_deu_monthly = models.FloatField(default=0)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
