C
C
connor742015-08-12 08:44:38
Django
connor74, 2015-08-12 08:44:38

Need help with Django ORM (formulate query)?

Good afternoon!
There are some models:

class Binds(models.Model):
...
    name = models.CharField()
...

class Repayment(models.Model):
...
    bond = models.ForeignKey('Bonds')
    date_repay = models.DateField()
    type_repay = models.CharField(choise=REPAY_T)
...

In the Repayment table, there may be several values ​​for one record from Bond, there may be one, or there may be none.
You must select for the record from the Bond table the corresponding record from the Repayment table (if it exists) so that the record meets the following criteria: date_repay is greater than today and would be the first date from today. Those. if just datr_repay is more than today (08/12/15), then both 10/13/15 and 02/10/18, 06/20/20 ... and so on can fall under this criterion.
You need exactly one record with a date greater and nearest than today.
For one Bond record, there cannot be several records with the same date in Repayment.
Thanks in advance!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Stanislav Fateev, 2015-08-12
@svfat

So what?

bond = Repayment.objects.filter(date_repay__gt=datetime.now()).order_by("date_repay")[0].bond

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question