Mantis
Mantis

Reputation: 1387

month + date in Django queryset

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(?)

Upvotes: 0

Views: 73

Answers (1)

coolharsh55
coolharsh55

Reputation: 1199

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

Upvotes: 1

Related Questions