Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
488 B
6
Indexable
class StorageToSellHistory(models.Model):
    storage = models.ForeignKey(Storage, on_delete=models.SET_NULL, null=True)
    sell_history = models.ForeignKey(SellHistory, on_delete=models.SET_NULL, null=True)

    def save(self, *args, **kwargs):
        storage = self.storage
        if storage.storage_amount > 0:
            storage.storage_amount -= 1
            storage.sold_amount += 1
            storage.save()
            super(StorageToSellHistory, self).save(*args, **kwargs)