Answer the question
In order to leave comments, you need to log in
Django - how to write off quantity from one model to another?
Hello!
There is a model:
class Material(models.Model):
name = models.CharField("Материал:", max_length=100)
coming = models.IntegerField(u"Приход Кол-во")
balance = models.IntegerField(u"Остаток Кол-во")
class Plot(models.Model):
plot = models.CharField("Участок:", max_length=100)
material = models.ForeignKey(Material, verbose_name=u"Материал")
expenditure = models.IntegerField(u"Израсходование Кол-во Материала")
def amount(self):
try:
calculation = ((self.material.coming) - (self.expenditure))
return "%d" % calculation
except:
return False
@receiver(pre_save, sender=Plot)
def total(sender, instance, **kwargs):
instance.material.balance = instance.calculation()
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question