How to sum up a field of different classes and different apps?

Asked

Viewed 122 times

0

Hello, I have a class in a Django app called product:

class produto(models.Model):
    descricao = models.CharField(max_length=150)
    quantidade = models.PositiveIntegerField()
    valor = models.DecimalField(max_digits=5, decimal_places=2)
    def __str__(self):
        return str(self.descricao)

and I have another class in an app called stock that will be responsible for buying products and consequently will update the product.quantity above!! the stock class below

class estoque(models.Model):
    item = models.ForeignKey(produto, on_delete=models.CASCADE)
    unidade = models.PositiveIntegerField()

    def __str__(self):
        return str(self.item)

how to add the amount of product per unit of stock once the previous balance will be added to the new purchase?? pardon if I was not very clear in the question

  • How to add where? In a view? In the properties of any of the models? You need to edit the question and show what you’re trying to do and what mistake you found.

  • is a stock control, I want to add more products and as I add the amount field of the product is changed (added to the amount I bought) understand?

  • I’m still unclear. Where are the two apps? How do the two apps communicate?

  • understand!! a friend said that my problem I solve with Django Signals, are two apps of the same project!! Fild App Stock Unit Will Update App Quantity Field Product!!

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.