Skip to content

Commit 2842886

Browse files
authored
Fixed #200 -- Fixed performance regression in RequestQuerySet.month().
Regression in 0adc76d.
1 parent 9adb3c4 commit 2842886

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@
1616

1717
* Confirms support for Django 2.2.
1818

19+
### Bug Fixes
20+
21+
* Fixes a performance regression in the admin's requests overview (#200).
22+
1923
## 1.5.5.
2024

2125
### Breaking

request/managers.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import datetime
33
import time
44

5+
from dateutil.relativedelta import relativedelta
56
from django.db import models
67
from django.db.models import Q
78
from django.utils import timezone
@@ -39,7 +40,11 @@ def month(self, year=None, month=None, month_format='%b', date=None):
3940
# Truncate to date.
4041
if isinstance(date, datetime.datetime):
4142
date = date.date()
42-
return self.filter(time__year=date.year, time__month=date.month)
43+
# Calculate first and last day of month, for use in a date-range
44+
# lookup.
45+
first_day = date.replace(day=1)
46+
last_day = first_day + relativedelta(months=1)
47+
return self.filter(time__gte=first_day, time__lt=last_day)
4348

4449
def week(self, year, week):
4550
try:

0 commit comments

Comments
 (0)