Ticket #23242 -- Approximate date_hierarchy

155 views
Skip to first unread message

Gavin Wahl

unread,
Aug 29, 2015, 4:50:20 PM8/29/15
to django-d...@googlegroups.com
I'm going to fix ticket #23242 by adding an option to approximate the date_hierarchy options instead of calculating them exactly. The implementation is straightforward but I'm not sure what the interface should be. 

The basic idea is instead of doing `SELECT DISTINCT date_trunc('year', created_at) FROM table`, then a date_trunc('month', created_at) to get the list of months, and so on, you can find the range with `SELECT date_trunc('year', max(created_at)), date_trunc('year', min(creeated_at))` and just assume that every year/month/day in between is filled in.

How should this feature be enabled? Should it be possible to approximate the year list, but once you've selected the year switch to exact? I'm thinking something like:

- approximate_date_hierarchy = False # default
- approximate_date_hierarchy = 1 # approximate years only
- approximate_date_hierarchy = 2 # approximate months and years
- approximate_date_hierarchy = 3 or True # approximate days, months, and years

Tim Graham

unread,
Aug 31, 2015, 2:54:21 PM8/31/15
to Django developers (Contributions to Django itself)
This seems okay at first glance, though I wonder if an enum-like object might be better than magic int/boolean values. Something like:

class ApproximateWith(object):
    NONE = 0
    YEARS = 1
    MONTHS = 2
    DAYS = 3

Do you think a separate ModelAdmin attribute better than allowing something like:

date_hierarchy = ('pub_date', ApproximateWith.YEARS)

Values that can be string or tuple have contributed to bugs in the past, but I thought it might be worth proposing.

Gavin Wahl

unread,
Sep 10, 2015, 12:21:29 PM9/10/15
to Django developers (Contributions to Django itself)
The enum seems fine. Where should it be defined? Should the docs mention the integer values at all, or are you required to use the enum?

I don't think setting date_hierarchy to a tuple is any cleaner.

Gavin Wahl

unread,
Sep 19, 2015, 12:38:10 AM9/19/15
to Django developers (Contributions to Django itself)
Is it going to be possible to get this in before the feature freeze?

Tim Graham

unread,
Sep 19, 2015, 7:46:23 AM9/19/15
to Django developers (Contributions to Django itself)
Another idea: instead of an enum, how about using the datetime.date.year, month, day attributes?

If you prefer the enum, I don't really see an obvious place for it, so use your best judgment and make it importable from contrib.admin I suppose.
Reply all
Reply to author
Forward
0 new messages