On 9/25/07, Michael <[EMAIL PROTECTED]> wrote: > <snip> > Using SQLite I can pull out the data I want using a query along the > line of: > > select * from event where date(event_date) in > ( > select date(event_date) from event > group by 1 order by 1 desc > limit 5 > ); > > Now, the problem is > 1) I'm not clear on how this query translates to Django's Database API > and
Sounds like it should be doable with extra [1]. Completely untested, but you get the idea: from django.db import connection opts = Event._meta Event.objects.extra(where=[""" DATE(%(event)s.%(date)s) IN ( SELECT DISTINCT DATE(%(event)s.%(date)s) FROM %(event)s ORDER BY 1 DESC %(limit)s )""" % { 'event': connection.ops.quote_name(opts.db_table), 'date': connection.ops.quote_name(opts.get_field('date').column), 'limit': connection.ops.limit_offset_sql(5), }]) > 2) If it does translate, how can I print out the day (as shown above > in the example output) before each sequence of events? is this > something I can do within a template? Use the {% ifchanged %} tag [2] (obviously, you'd be formatting the date whatever way you want it instead): {% for event in events %} {% ifchanged %}{{ event.date }}{% endifchanged %} {% endfor %} Jonathan. [1] http://www.djangoproject.com/documentation/db-api/#extra-select-none-where-none-params-none-tables-none [2] http://www.djangoproject.com/documentation/templates/#ifchanged --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---