1
I am trying to create a table of installments, in which the user will inform the purchase value, input (if you have), the amount of installments and the date of purchase. With this data I have to take the date of purchase and show the dates that the user should pay.
First Problem - I’m not able to put in the BD the installment because it generates the error Valueerror: Cannot assign "<class 'calendario.models.Compras'>": "Parcelamento.compras" must be a "Compras" instance..
Second problem - I have no idea how to put the date list in the comic book.
my models.py:
class Compras(models.Model):
nome_compra = models.CharField(max_length=200)
valor_compra = models.FloatField()
entrada = models.FloatField()
data_compra = models.DateField()
tipo_parcelamento = models.IntegerField()
quantidade_parcelas = models.IntegerField()
data_criacao = models.DateTimeField(auto_now=True)
def __str__(self):
return self.nome_compra
class Parcelamento(models.Model):
compras = models.ForeignKey(Compras, on_delete=models.CASCADE)
valor_parcela = models.FloatField()
data_parcelas = models.DateField()
In my utils.py
def gravar_dados(**kwars):
nome_compra, valor_compra, entrada, data_compra, tipo_parcelamento, quantidade_parcelas = kwars.values()
Compras.objects.create(nome_compra=nome_compra,
valor_compra=valor_compra,
entrada=entrada,
data_compra=data_compra,
tipo_parcelamento=tipo_parcelamento,
quantidade_parcelas=quantidade_parcelas,
)
valor_parcela = (valor_compra - entrada) / quantidade_parcelas
Parcelamento.objects.create(compras=Compras,
valor_compra=valor_parcela,
data_parcelas=,
)
where on that parcel date, was to pick up the dates I have to calculate.
Thank you very much, our arrival gave me a lively your reply, I will be changing my code to carry out the changes you gave me. Thank you very much So answering your question regarding variable installation_type, which the user inform will have 3 types of installments, daily (input + 1 installment), fortnightly (15 days to pay) and monthly (default)then I’ll calculate the benefits on top of that information.
– Raul Gomes