我有一個名爲Fattura的模型,我想將字段「printable」的默認值設置爲包含字段「numero」的值的字符串。django將模型字段的默認值設置爲自身屬性
但我有錯誤,link_fattura有較少的參數,但如果我添加默認= link_fattura(self)我有一個錯誤,因爲自我沒有定義。
我該如何解決這個問題?
class Fattura(models.Model):
def link_fattura(self, *args, **kwargs):
return u"http://127.0.0.1:8000/fatture/%s/" % (self.numero)
data = models.DateField()
numero = models.CharField("Numero", max_length=3)
fatturaProForma = models.ForeignKey(FatturaProForma)
printable = models.CharField("Fattura stampabile", max_length=200, default=link_fattura)
def __unicode__(self):
return u"%s %s" % (self.data, self.numero)
class Meta:
verbose_name_plural = "Fatture"
ordering = ['data']