I am working on a project that has an Investment and Invoice class in the models.py. The way they work is that a user places an investment and while saving the Investment model creates an invoice. Here is the relevant code:
class Investment(models.Model):
...
def save(self, *args, **kwargs):
current_investment = Investment.objects.get(pk=self.pk)
create_invoice = Invoice.objects.create(investment=current_investment,
fee_type='Mngmt.',
amount=self.amount*fee_amount)
class Invoice(models.Model):
user = models.ForeignKey(User)
investment = models.ForeignKey(Investment)
fee_type = models.CharField(max_length=24)
amount = models.DecimalField(max_digits=12, decimal_places=2, default=0)
date = models.DateTimeField(default=timezone.now, blank=True)
def __str__(self):
return self.investment.fund.name
So basically when the Investment class is saved an Invoice object is created, however I want to get the current user and set it to the user field in the Invoice class. Any ideas on how I can get this done? Thanks.