I have 3 tables, a relation many to many. 1 is INVOICE 1 Product(as category) and the middle one who links them. I need in the middle table to get also the "price" from product table not only the name; because i have an inline form and when i select the product name i would like the price to appear without the user to type it in. Can someone help ?
my email so i can send the code: tosadenisandrei@gmail.com
#models.py
class Product(models.Model):
category = (
('Choose category', 'Choose category'),
('Small parts', 'Small parts'),
('Big parts', 'Big parts'),
('Material', 'Material'),
('Wheels', 'Wheels')
)
category = models.CharField(max_length=20, choices=category, default='Choose category')
product_name = models.CharField(max_length=30)
rate = models.DecimalField(default=0, max_digits=10, decimal_places=2)
net_amount = models.DecimalField(default=0, max_digits=10, decimal_places=2)
gross_amount = models.DecimalField(default=0, max_digits=10, decimal_places=2)
# tax = models.DecimalField(default=0, max_digits=10, decimal_places=2)
# commission = models.IntegerField(default=0)
bar_code = models.CharField(max_length=40, default='')
description = models.CharField(max_length=200)
# @property
# def get_special_combination_value(self):
# return '{}{}'.format(self.product_name, self.rate)
def __str__(self):
return self.product_name
class ProductTry(models.Model):
type = (('item', 'Item'),
('service', 'Service')
)
product = models.ForeignKey(Product, blank=True, null=True, on_delete=models.CASCADE)
invoice_id = models.ForeignKey(Invoice, blank=True, null=True, on_delete=models.CASCADE)
measurements_selling = models.CharField(max_length=50, default='item', choices=type, null=False)
quantity = models.DecimalField(max_digits=10, decimal_places=2)
# formular_price = models.ForeignKey(Product.rate, blank=True, null=True, on_delete=models.CASCADE)