Fixed #31590 -- Fixed ModelAdmin.date_hierarchy crash with an empty QuerySet.
Regression in 55cdf6c52d
.
This commit is contained in:
parent
9d211f149a
commit
099bce1bf0
|
@ -380,12 +380,12 @@ def date_hierarchy(cl):
|
|||
# select appropriate start level
|
||||
date_range = cl.queryset.aggregate(first=models.Min(field_name),
|
||||
last=models.Max(field_name))
|
||||
if date_range['first'] and date_range['last']:
|
||||
if dates_or_datetimes == 'datetimes':
|
||||
date_range = {
|
||||
k: timezone.localtime(v) if timezone.is_aware(v) else v
|
||||
for k, v in date_range.items()
|
||||
}
|
||||
if date_range['first'] and date_range['last']:
|
||||
if date_range['first'].year == date_range['last'].year:
|
||||
year_lookup = date_range['first'].year
|
||||
if date_range['first'].month == date_range['last'].month:
|
||||
|
|
|
@ -969,6 +969,11 @@ class AdminViewBasicTest(AdminViewBasicTestCase):
|
|||
self.assertEqual(response.context['site_url'], '/my-site-url/')
|
||||
self.assertContains(response, '<a href="/my-site-url/">View site</a>')
|
||||
|
||||
def test_date_hierarchy_empty_queryset(self):
|
||||
self.assertIs(Question.objects.exists(), False)
|
||||
response = self.client.get(reverse('admin:admin_views_answer2_changelist'))
|
||||
self.assertEqual(response.status_code, 200)
|
||||
|
||||
@override_settings(TIME_ZONE='America/Sao_Paulo', USE_TZ=True)
|
||||
def test_date_hierarchy_timezone_dst(self):
|
||||
# This datetime doesn't exist in this timezone due to DST.
|
||||
|
|
Loading…
Reference in New Issue