Filtering data by date range

128 views Asked by At

I have my payment model I what to be able to select by date

class LeasePayment(CommonInfo):
    version = IntegerVersionField( )
    amount  = models.DecimalField(max_digits=7, decimal_places=2)
    lease = models.ForeignKey(Lease)
    leaseterm = models.ForeignKey(LeaseTerm)
    payment_date = models.DateTimeField()
    method = models.CharField(max_length=2, default='Ch',
                              choices=PAYMENT_METHOD_CHOICES)

Basically I want to be able to input 2 dates and display all the data between them . Righ now I started to implement this solution https://groups.google.com/forum/#!topic/django-filter/lbi_B4zYq4M based on django_filter. However since the task is pretty trivial was wondering if there an easier way.

1

There are 1 answers

0
neverwalkaloner On

Try to use date__range it will return data from database in selected date interval:

LeasePayment.objects.filter(payment_date__range=[start_date, end_date])