0

In my Django app I am trying to export an excel reports by month created. The excel part works fine but I am unsure on how to filter by the month created.

model.py

class Claim(models.Model):
    ....
    creation = models.DateField(auto_now_add=True)

urls.py

url(r'^download/(?P<year>\d{4})/(?P<month>\d{2})/$', download_workbook), 

views.py

def download_workbook(request, year, month):
    queryset = Claim.objects.filter(?)

1 Answer 1

1

try this: (from django documentation 1.8)

data = Claim.objects.filter(
    creation__year=someyear,
    creation__month=somemonth,
)

p.s. use Field Lookups to filter data based on field type

1
  • :o that simple. Thanks
    – Mantis
    Sep 10, 2015 at 10:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.