1👍
✅
invoice.save()
do not return the instance. You should get pk
right from the invoice
variable:
def save(self):
data = self.cleaned_data
invoice = Invoice(invoice_issued_on=data['invoice_issued_on'])
invoice.save()
return invoice # invoice.pk will contain id of the object
BTW, there is much shorter version of object creation:
def save(self):
data = self.cleaned_data
return Invoice.objects.create(invoice_issued_on=data['invoice_issued_on'])
Source:stackexchange.com