From: Philippe N. <sw...@fr...> - 2004-06-02 12:08:23
|
Hi, I need to sort and count SQLObjects per date. An example might really show what I want :) class Article(SQLObject): date = DateTimeCol() ... I have many many Articles, and I'd like to build a Calendar showing how many articles were published by month and/or year. For instance: 10 articles on 05/22 3 articles on 05/14 I see one durty solution which would like this (untested) : calendar = {} # keys: day numbers of the month for article in Article.select(orderBy=Article.q.date): if article.getYear() != 2004 or article.getMonth() != 5: continue try: calendar[article.getDay()] += 1 except KeyError: calendar[article.getDay()] = 1 it isn't really efficient because it fetches all articles. Is there a clean way to select SQLObjects given a specific date interval on DateTimeCol ? Philippe |