On Fri, Sep 11, 2015 at 1:15 PM, Wannabe Coder <cynical.sav...@gmail.com> wrote: > Hello everyone! > > I already created a ticket detailing my use case, and one of the developers > pointed me to this discussion group. I am not quite satisfied with the > response I got since the DateTransforms that will be released in Django 1.9 > only appear to extract year/month/day/etc numbers and do not seem to be able > to annotate based on generated time periods from a series of > dates/datetimes. Basically what I can do with .extra() right now is generate > a table like the ones shown in my screenshots. > > I hope that behavior would be possible to customize or even include in > Django 1.9 out of the box. Thanks!
I think you have slightly misunderstood. The Expressions and Transform API allows *you* to create user defined expressions and transformations. Yes, there are some new built in expressions and transformations available, but the real power is allowing you to define such a transformation in a reusable way, rather than hacking it in to extra() like you currently have to do in each place you want to use it. So you want an expression that is like MonthTransform, but using DATE_TRUNC() instead of MONTH()? Have at it! It's a documented API: https://docs.djangoproject.com/en/dev/ref/models/lookups/#transform-reference The DB backends operations class even support a datetime_trunc_sql() (compare with the implementation of DateTransform, base class of MonthTransform) https://github.com/django/django/blob/master/django/db/models/fields/__init__.py#L2432 Cheers Tom -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at http://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAFHbX1KfNPY2mHUR3A1WtsrQ1qfJxKYnVFJb%3DQBTSgt2Om%2B%3D%2BQ%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.