Issue
In models.py
class loan(models.Model):
completed=models.BooleanField(default=False)
created_at = models.DateTimeField(auto_now_add=True,null=True)
application_id=models.CharField(max_length=100,unique=True)
class topay(models.Model):
loanapplication=models.ForeignKey(loan,on_delete=models.CASCADE,null=True)
paymentdate=models.DateField(null=True, blank=True)
How to get last paymentdate for every loan application
In views.py
topay.objects.filter().values().annotate(last=Max('paymentdate'))
Solution
to get each loan
latest topay
you can filter like this
loan.objects.annotate(
maxpaydate=Max("topay__paymentdate"),
).values("id", "maxpaydate")
Answered By - Ali Aref
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.