I have some classes like these;
class RawMaterial(models.Model):
name = models.CharField(max_length=100)
class Product(models.Model):
name = models.CharField(max_length=100)
amount = models.IntegerField()
raw_materials = models.ManyToManyField(RawMaterial, through='MaterialProduct', related_name='products')
class MaterialProduct(models.Model):
raw_material = models.ForeignKey(RawMaterial, on_delete=models.CASCADE)
product = models.ForeignKey(Product, on_delete=models.CASCADE)
material_price = models.FloatField()
material_rate = models.FloatField()
I want to write a method which name is calculate_total_price
, My method will use Product's amount
and MaterialProduct's material_price
, material_rate
.
To design a proper/beautiful/maintainable project, where should I write my method? To models.py
or views.py
?
Thanks in advance.