Django DateTimeRangeField used with date_hierarchy

13 views
Skip to first unread message

Laurence Sonnenberg

unread,
Oct 3, 2017, 10:32:02 AM10/3/17
to Django users
Hi 

It's great that with 1.11 django.contrib.admin and django.contrib.postgres have brought the ability to use date_hierarchy with fields from other connected tables.

I was wondering if the ability to to create a transform on a given table existed so that fields other than DateField or DateTimeField could be used? For example DateTimeTZRange. Or perhaps it could be done in the postgresql backend?

A transform example might be: 

@admin.register(models.MyModel)
class MyModelAdmin(AdvancedModelAdmin):

    date_hierarchy = 'date_range_to_datetime'

    def date_range_to_datetime(instance):
        """
        Return a datetime from django date range.
        """
        return instance.range.lower

Is there anyone who might have some insight into how this could be done?
Reply all
Reply to author
Forward
0 new messages