Ticket #13607: date_hierarchy_initialisation.3.diff

File date_hierarchy_initialisation.3.diff, 1.1 KB (added by DrMeers, 5 years ago)

Include check in case of empty querysets

  • django/contrib/admin/templatetags/admin_list.py

     
    225225
    226226        link = lambda d: cl.get_query_string(d, [field_generic])
    227227
     228        if not (year_lookup or month_lookup or day_lookup):
     229            # select appropriate start level
     230            date_range = cl.query_set.aggregate(first=models.Min(field_name),
     231                                                last =models.Max(field_name))
     232            if date_range['first'] and date_range['last']:
     233                if date_range['first'].year == date_range['last'].year:
     234                    year_lookup = date_range['first'].year
     235                    if date_range['first'].month == date_range['last'].month:
     236                        month_lookup = date_range['first'].month
     237       
    228238        if year_lookup and month_lookup and day_lookup:
    229239            day = datetime.date(int(year_lookup), int(month_lookup), int(day_lookup))
    230240            return {
Back to Top