Hello everyone, Im trying to get the last payment from each user:
Here is my model:
class Payment(models.Model):
id = models.AutoField(primary_key=True)
user = models.ForeignKey(User, on_delete=models.DO_NOTHING)
amount = models.DecimalField(max_digits=7, decimal_places=2, default=‘0.00’)
class Student(models.Model):
id=models.AutoField(primary_key=True)
user=models.OneToOneField(User, on_delete=models.CASCADE, null=True)
Explanation:
One user has many payments. What i need is to get the last record of payment of the user to validate when he realized his last payment. What method or logic i need to use. Can anybody help me? Thanks.
Are you looking to get the most recent payment for all students, or are you looking to retrieve the most recent payment for a single student? (Or are you looking to get the most recent payment for the person who is currently logged on and looking at that page?)