Re: list of all months where objects are
Hello Grigory Fateyev! On Thu, 20 Jul 2006 15:50:22 +0400 you wrote: > > Hello James Bennett! > On Wed, 19 Jul 2006 11:32:00 -0500 you wrote: > > > > > On 7/19/06, Grigory Fateyev <[EMAIL PROTECTED]> wrote: > > > Now I do like so: [...] Maybe I cann't find any mistake? -- ÷ÓÅÇÏ ÎÁÉÌÕÞÛÅÇÏ! greg [at] anastasia [dot] ru çÒÉÇÏÒÉÊ. --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Re: list of all months where objects are
Hello James Bennett! On Wed, 19 Jul 2006 11:32:00 -0500 you wrote: > > On 7/19/06, Grigory Fateyev <[EMAIL PROTECTED]> wrote: > > Now I do like so: [...] > > Unless I'm missing something, what you want is: > > date_list = [] > year_list = Article.objects.order_by('-pub_date').dates('pub_date', > 'year') for y in year_list: > date_list.append({'year': y.year, 'months': > Article.objects.filter('pub_date__year__exact=y.year').order_by('-pub_date').dates('pub_date', > 'month')}) > > And then iterate in the template like this: > > {% for dl in date_list %} > {{ dl.year }} > > {% for month in dl.months %} > {{ month|date:"%B" }} > {% endfor %} > > {% endfor %} > > Admittedly, I'm not entirely awake and alert right now (got no sleep > last night), but that feels like the right solution. > Thanks for helping. dates_list = [] year_list=Article.objects.all().order_by('-pub_date').dates('pub_date','year') for y in year_list: row = {'year': y.year, 'months':Article.objects.filter(pub_date__contains='y.year').order_by('-pub_date').dates('pub_date','month')} dates_list.append(row) print date_list return: [{'months': [], 'year': 2002}, {'months': [], 'year': 2003}, {'months': [], 'year': 2004}, {'months': [], 'year': 2005}] [{'months': [], 'year': 2002}, {'months': [], 'year': 2003}, {'months': [], 'year': 2004}, {'months': [], 'year': 2005}, {'months': [], 'year': 2006}] like empty months, but at that time in api: >>> Article.objects.filter(pub_date__contains='2005').order_by('-pub_date').dates('pub_date','month') [datetime.datetime(2005, 1, 1, 0, 0), datetime.datetime(2005, 2, 1, 0, 0), datetime.datetime(2005, 3, 1, 0, 0), datetime.datetime(2005, 4, 1, 0, 0), datetime.datetime(2005, 5, 1, 0, 0), datetime.datetime(2005, 6, 1, 0, 0), datetime.datetime(2005, 7, 1, 0, 0), datetime.datetime(2005, 8, 1, 0, 0), datetime.datetime(2005, 9, 1, 0, 0), datetime.datetime(2005, 10, 1, 0, 0), datetime.datetime(2005, 11, 1, 0, 0), datetime.datetime(2005, 12, 1, 0, 0)] and, of course, months in templates is empty. Why it can be? This question is not clear django, but think will be interesting for many people. -- ÷ÓÅÇÏ ÎÁÉÌÕÞÛÅÇÏ! greg [at] anastasia [dot] ru çÒÉÇÏÒÉÊ. --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Re: list of all months where objects are
On 7/19/06, Grigory Fateyev <[EMAIL PROTECTED]> wrote: > Now I do like so: > [...] > y=Article.objects.all().order_by('-pub_date').dates('pub_date','year') > m=Article.objects.all().order_by('-pub_date').dates('pub_date','month') Unless I'm missing something, what you want is: date_list = [] year_list = Article.objects.order_by('-pub_date').dates('pub_date', 'year') for y in year_list: date_list.append({'year': y.year, 'months': Article.objects.filter('pub_date__year__exact=y.year').order_by('-pub_date').dates('pub_date', 'month')}) And then iterate in the template like this: {% for dl in date_list %} {{ dl.year }} {% for month in dl.months %} {{ month|date:"%B" }} {% endfor %} {% endfor %} Admittedly, I'm not entirely awake and alert right now (got no sleep last night), but that feels like the right solution. -- "May the forces of evil become confused on the way to your house." -- George Carlin --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Re: list of all months where objects are
Hello Adrian Holovaty! On Wed, 19 Jul 2006 10:10:20 -0500 you wrote: > > On 7/19/06, Grigory Fateyev <[EMAIL PROTECTED]> wrote: > > I want to get list of all months where objects present. First of > > all, using date_based generic views I could not extra_context > > additional like 'date_list', but decide to use my own view def. > > Hi Grigory, > > You can use the dates() QuerySet method to do this. Example: > > Article.objects.dates('pub_date', 'month') > > Here are the docs: > > http://www.djangoproject.com/documentation/db_api/#dates-field-kind-order-asc Thanks, Adrian, for replying. Now I do like so: [...] y=Article.objects.all().order_by('-pub_date').dates('pub_date','year') m=Article.objects.all().order_by('-pub_date').dates('pub_date','month') return render_to_response('articles/articles_list.html', { 'object_list': l, 'year_list': y, 'month_list': m, [...] and template: {% for year in year_list %} {{ year|date:"Y" }} {% for month in month_list %} {{month|date:"F"}} {% endfor %} {% endfor %} This gives me: 2002 list of all months 2003 list of all months 2004 list of all months 2005 list of all months but it should be: 2002 list of months in 2002 2003 list of months in 2003 2004 list of months in 2004 2005 list of months in 2005 How fix this behavior? Sorry, if my explanations looks very stupid :) -- ÷ÓÅÇÏ ÎÁÉÌÕÞÛÅÇÏ! greg [at] anastasia [dot] ru çÒÉÇÏÒÉÊ. --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Re: list of all months where objects are
On 7/19/06, Grigory Fateyev <[EMAIL PROTECTED]> wrote: > I want to get list of all months where objects present. First of all, > using date_based generic views I could not extra_context additional > like 'date_list', but decide to use my own view def. Hi Grigory, You can use the dates() QuerySet method to do this. Example: Article.objects.dates('pub_date', 'month') Here are the docs: http://www.djangoproject.com/documentation/db_api/#dates-field-kind-order-asc Adrian -- Adrian Holovaty holovaty.com | djangoproject.com --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
list of all months where objects are
Hello, djangolers! I want to get list of all months where objects present. First of all, using date_based generic views I could not extra_context additional like 'date_list', but decide to use my own view def. def list_articles(request): list_a = Article.objects.all().order_by('-pub_date') y = list_a.dates('pub_date','year') # Here I want to get months of every year m = [y for month in list_a] and template should be like: {% for year in year_list %} {{ year|date:"Y" }} {% for month in month_list %} {{month|date:"F"}} {% endfor %} {% endfor %} How can I do this? Thanks. -- ÷ÓÅÇÏ ÎÁÉÌÕÞÛÅÇÏ! greg [at] anastasia [dot] ru çÒÉÇÏÒÉÊ. --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---