I need adding records within another model

12 views
Skip to first unread message

Jack Gonzales

unread,
Mar 13, 2019, 5:24:00 PM3/13/19
to Django users
Hi everyone, i have two classes in my model.py, this system is for registering the payments of an account, for instance, a client is lent 1000 dollars and that account has an ID, each loan has an ID and what i want is when the client makes the payment of his fees i can register each ammount and that every payment is linked with the ID of the account, 1000 dollars could be 10 payments of 100 dollars and that 10 records are linked to that account and the same for all loans, every loan with its records of payment. I hope that you've could understand and help me.
 

## THIS IS THE MODEL OF LOANS DATA WHERE THE DATA OF LOAN IS STORED.
class LoansData(models.Model):
"""
Profile model.

Proxy model that extend the base data
with other informarion.
"""

customer = models.ForeignKey(CustomerData, on_delete=models.CASCADE)
ammount = models.PositiveIntegerField(default=0)
interest = models.DecimalField(max_digits=3, decimal_places=2)
total = models.PositiveIntegerField(editable=False)

uid = models.CharField('UUID', max_length=5, help_text='5 characters', blank=True)

created = models.DateField(auto_now_add=True)
modified = models.DateTimeField(auto_now=True)

def save(self, *args, **kwargs):
self.total = self.ammount + (self.ammount*self.interest)
super(LoansData, self).save(*args, **kwargs)



class Meta:
verbose_name = 'Loan Data'
verbose_name_plural = 'Loans Data'

def __str__(self):
""" Return username """

return str(self.pk)





#THIS IS WHAT I CREATED FOR ADDING THE RECORDS OF EVERY PAYMENT THE CLIENT MAKES TO ITS RESPECTIVE ACCOUNT OF LOAN. BUT IF IT'S NECESSARY CHANGE THIS IT DOESN'T MATTER.

class LoanInstance(models.Model):

"""
This represents the status up to date of loan
"""
id = models.UUIDField(primary_key=True, default=uuid.uuid4, help_text="Uniquie ID for every single payment." )
loan = models.ForeignKey('LoansData', on_delete=models.CASCADE, null=True)
date = models.DateField(auto_now_add=True)
ammount = models.PositiveIntegerField(default=0)

def __str__(self):
""" Return id """
return '%s' % (self.id)



###################################333

I REALLY HOPE THAT YOU CAN HELP ME PLEASE. I'M STUCK WITH THIS.

Reply all
Reply to author
Forward
0 new messages