Модели Django с обратным полем
У меня есть проблема, которую я, кажется, не могу решить. У меня есть 2 модели с ForeignKey
, как показано ниже :
class Transaction(models.Model):
chp_reference = models.CharField(max_length=50, unique=True)
rent_effective_date = models.DateField(null=True, blank=True)
income_period = models.CharField(max_length=11, choices=income_period_choices)
property_market_rent = models.DecimalField( help_text="Weekly", max_digits=7)
class FamilyGroup(models.Model):
Transaction= models.ForeignKey(Transaction, on_delete=models.CASCADE, related_name="family_groups")
last_rent = models.DecimalField(max_digits=7, decimal_places=2) income_period = models.CharField(max_length=11, choices=income_period_choices)
any_income_support_payment = models.BooleanField(null=True, blank=True)
@property
def rent_charged(self):
rent_charged = self.transaction.property_market_rent - self.last_rent
now this function is good for only one instance of FamilyGroup
, what I trying to do is to Subtract this rent_charged
from self.transaction.property_market_rent
in the next instance of FamilyGroup
, so the next instance of FamilyGroup
can have something like :
@property
def rent_charged(self):
rent_charged = self.transaction.property_market_rent - rent_charged #( of the first instance) - self.last_rent
Любые мысли были бы очень признательны!