I'm new in Django, got a problem. I have a method in Commodity Model:
@transaction.atomic
def payment(self):
if self.owner.balance > self.price and self.active is False:
self.act_time_till = now() + timedelta(days=1)
self.owner.balance -= self.price
# here i need to create a new Invoice object
self.save()
return True
else:
return False
And I have a different model - Invoice:
class Invoice(models.Model):
commodity = models.ForeignKey(Commodity, on_delete=models.PROTECT)
paid_till = models.DateTimeField(blank=False, null=False)
value = models.DecimalField(max_digits=3, decimal_places=2, blank=False, null=False)
How can I create an instance of Invoice every time I make payment? Thanks!
Invoice.objects.create(**data), also you could use this anywhere you needed