2👍
You can’t do this using the default
argument. The best bet is to override the save
method:
def save(self, *args, **kwargs):
if not self.id and not self.printable:
self.printable = self.link_fattura()
return super(Fattura, self).save(*args, **kwargs)
0👍
Sorry I read you question wrong, that’s not possible without javascript because your model hasn’t been saved at that stage yet.
You could forecast the url by doing something like:
def link_facttura(self):
if not self.id:
return some_url/fattura/%d/ % Fattura.objects.latest().id+1
return u""
But it’s ugly and likely to cause erros once you start deleting records
- [Answered ]-Integrate Visa and Mastercard in DJango 1.8 app
- [Answered ]-Adjust django forms – Comment Form CSS
- [Answered ]-Temporary modify model's field value in Django
- [Answered ]-Count(*) as in Django Orm
Source:stackexchange.com