Code

Ticket #13607: date_hierarchy_initialisation.2.diff

File date_hierarchy_initialisation.2.diff, 958 bytes (added by DrMeers, 4 years ago)

Oops, can't use "any" yet...

Line 
1Index: templatetags/admin_list.py
2===================================================================
3--- templatetags/admin_list.py  (revision 13402)
4+++ templatetags/admin_list.py  (working copy)
5@@ -225,6 +225,15 @@
6 
7         link = lambda d: cl.get_query_string(d, [field_generic])
8 
9+        if not (year_lookup or month_lookup or day_lookup):
10+            # select appropriate start level
11+            date_range = cl.query_set.aggregate(
12+                first=models.Min(field_name), last=models.Max(field_name))
13+            if date_range['first'].year == date_range['last'].year:
14+                year_lookup = date_range['first'].year
15+                if date_range['first'].month == date_range['last'].month:
16+                    month_lookup = date_range['first'].month
17+       
18         if year_lookup and month_lookup and day_lookup:
19             day = datetime.date(int(year_lookup), int(month_lookup), int(day_lookup))
20             return {