On Wed, Apr 1, 2009 at 11:02 PM, Nicolas Lara <[email protected]> wrote: > > > On Wed, Apr 1, 2009 at 2:29 PM, Russell Keith-Magee <[email protected]> > wrote: >> >> On Wed, Apr 1, 2009 at 12:31 PM, Max Veytsman <[email protected]> >> wrote: >> >> Hi Maxim, >> >> > There was a project idea in the wiki called "Improve Query Expressions >> > (F() syntax." >> > >> > Improvements to Handling of Dates >> > ================================== >> > >> > 1) Syntax for comparisons using fields derived from DateField >> > >> > For instance to select all of the items that were written before the >> > 10th of the month I would do >> > >> > Item.objects.filter(datetime_posted__day__lt=10) >> >> I'm not sure this is the best approach. It isn't consistent with any >> other filter operator in Django - for all other operators, the last >> part (__lt in this case) is the operator, and all other parts are >> considered to be fields that need to be joined. >> >> My preferred approach here would be to allow for annotations that are >> non-aggregates. This way, you would annotate the 'day' onto the item >> instances, then filter on that annotation: >> >> >> Item.objects.annotate(posted_day=Day('datetime_posted')).filter(posted_day__lt=10) >> >> This has the added advantage that it allows for user-specified >> annotations functions. > > The Day object syntax would result in a subquery. An interesting case here > would be to create a generic subquering annotation function that could be > extended or even a generic way of subquering. I'm not sure if this goes > completely out of scope. AFAIK, it has been discussed before but without > concluding about a syntax for generic subquering.
Why does it result in a subquery? This is really no different to F() - it's just a column reference, but with an SQL function wrapped around it that can extract the date value from the database column. The complication is with the implementation of annotate(). Under this approach, you can no longer assume that a clause in an annotate is automatically an aggregation, and should be treated as such. However, this should be a fairly minor implementation detail. Yours, Russ Magee %-) --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django developers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/django-developers?hl=en -~----------~----~----~----~------~----~------~--~---
