[Answered ]-How to find objects created within given date range?

2👍

Customer.objects.filter(Created__gte=datetime.date.today() - datetime.timedelta(days=7))

By the way, it is a good practice to create your model fields, template names, directories, functions etc. always with lowercase names.


from django.shortcuts import render

def recent_customers(request):
    customers = Customer.objects.filter(created__gte=datetime.date.today() - datetime.timedelta(days=7))
    return render(request, "customer/all_customers.html", {"customers": customers})

You might want to take a look at the style guide regarding naming convention rules in Python.

Leave a comment