class LenderInvestment(models.Model):
user = models.ForeignKey(User)
investment = models.DecimalField(max_digits=15, decimal_places=2, default=1000000)
initial_capital = models.DecimalField(max_digits=12, decimal_places=2, **optional)
def __unicode__(self):
return str(self.initial_capital)
class LoanDisbursement(models.Model):
user = models.ForeignKey(User)
initial_capital = models.OneToOneField(LenderInvestment)
loan_applicant = models.ForeignKey(LoanApplication)
money_disbursed = models.DecimalField(max_digits=10, decimal_places=2)
def __unicode__(self):
return str(self.user)
def loan_disbursement_receiver(sender, instance, *args, **kwargs):
initial_capital = instance.initial_capital
money_disbursed = instance.money_disbursed
initial_capital = Decimal(initial_capital) - Decimal(money_disbursed)
instance.initial_capital = initial_capital
pre_save.connect(loan_disbursement_receiver, sender=LoanDisbursement)
我有兩個模型如上所示序從一個模型實例的值,以計算到另一個模型實例我需要幫助,當我連接上面時,它給出了類型錯誤。期待着一些積極的答覆。類型錯誤(「無法轉換%R到十進制的」%值)類型錯誤:無法轉換<LenderInvestment:20000.00>爲十進制
請修復縮進。另外,你是否嘗試從'initial_capital' *中減去'money_disbursed'而不將*轉換爲小數? – elethan
不帶小數點的錯誤是不支持的操作類型爲 - :「LenderInvestment」和「小數」 – Biju