Re: Year/month archive help
Hmm what i've done so far is: in my view: def arhiva(requesst): arch = Post.objects.dates('data', 'month', order='DESC') archives = {} for i in arch: tp = i.timetuple() year = tp[0] month = tp[1] if year not in archives: archives[year] = [] archives[year].append(month) else: if month not in archives[year]: archives[year].append(month) return render_to_response('blog/arhiva.html', {'archives':archives}) and in my template: {% for years, months in archives.items %} {{ years }} {% for month in months %} {{ month }} {% endfor %} {% endfor %} this returns something like: 2008 10 2009 10 9 2007 10 first of all, i can't sort them of all...by year descending or enything...and how can i replace year months with names(translated because i'm from romania) and also so the months who does not have an entry? something like this http://www.flickr.com/photos/ionutgabriel/3990015411/ ? I really can't figure it out... Maybe someone can help me...thank you! --~--~-~--~~~---~--~~ 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 django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Year/month archive help
Hello, Check out Django's built-in "generic" views: http://docs.djangoproject.com/en/dev/ref/generic-views/ It sounds like this solution might work for you if you just want to show an archive of your Posts. With this, you don't have to write any views, you only have to configure the urls and templates. Good luck! On Oct 7, 1:31 pm, icrismariu wrote: > Hello, i'm new to Django and started an application, i did the models, > views, templates, but i want to add some kind of archive to the bottom > of the page, something like > thishttp://www.flickr.com/photos/ionutgabriel/3990015411/. > > My model looks like this: > > class Post(models.Model): > titlu = models.CharField(max_length=45) > continut = models.TextField() > imagine = models.CharField(max_length=150) > data = models.DateTimeField() > modificat = models.DateTimeField (blank = True, null = True) > > I know i have to loop trough the model and on the "data" field...i've > searched all day for a solution, but didn't find anything. > > I want to show the year, and the months, and only the months who have > entries to be links so i can redirect users to another view where they > can see only the posts from that month. > > How can i do this? > > Thank you for you're help! > > p.s. sorry for my English --~--~-~--~~~---~--~~ 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 django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Year/month archive help
Hello, i'm new to Django and started an application, i did the models, views, templates, but i want to add some kind of archive to the bottom of the page, something like this http://www.flickr.com/photos/ionutgabriel/3990015411/. My model looks like this: class Post(models.Model): titlu = models.CharField(max_length=45) continut = models.TextField() imagine = models.CharField(max_length=150) data = models.DateTimeField() modificat = models.DateTimeField (blank = True, null = True) I know i have to loop trough the model and on the "data" field...i've searched all day for a solution, but didn't find anything. I want to show the year, and the months, and only the months who have entries to be links so i can redirect users to another view where they can see only the posts from that month. How can i do this? Thank you for you're help! p.s. sorry for my English --~--~-~--~~~---~--~~ 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 django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---