1
I have the models "Subscriber":
class Assinante(models.Model):
name = models.CharField("Nome", max_length=32, null=False, blank=True)
phone = models.CharField("Telefone", max_length=11, null=True, blank=True)
email = models.EmailField("E-mail", null=True, blank=True)
plans = models.ForeignKey("Plano", null=True, blank=True)
start_date = models.DateField("Data da assinatura", null=False, blank=False)
due_date = models.DateField("Vencimento", null=False, blank=False)
def __str__(self):
return self.name
class Meta:
verbose_name_plural = "Assinantes"
And the models "Plan":
class Plano(models.Model):
name = models.CharField("Nome", max_length=32, null=False, blank=False, unique=True)
price = models.FloatField("Valor pago", default=00.00)
def __str__(self):
return self.name
class Meta:
verbose_name_plural = "Planos"
As it is possible to notice in "Subscriber" I have a foreign key referencing the "Plan" of the "Subscriber". What I want is to have a "Subscriber" field that stores the value of the variable price set in "Plan", but this value needs to be related to the table of the plan chosen in the variable plans, for example I registered a name plan Gold with the price 79.99, when I add a subscriber and set his plan as Gold I want to automatically value the column Amount paid is 79.99. Example below.
I need this to work on a Django-Admin table, can someone help me ?
Assinantes
| Nome | Telefone | E-mail | Planos | Valor pago |
| Carlos | 88 952684179 | [email protected] | Gold | 79,99 |
| Mario | 88 910101799 | [email protected] | Platinium | 119,99 |
Planos
| Plano | Preço |
| Prata | 29,99 |
| Gold | 79,99 |
| Platinium | 119,99 |
That’s exactly what I wanted, thank you very much helped me!
– adevontheroad
In this example, if I change the value of the plan all relationships are updated correct? but if I want new registrations to use the new value but active registrations he respects the original value has how? something like entering the value of the table and plans in the subscriber table?
– Rhuan Lima