On 12/3/06, Oliver Andrich <[EMAIL PROTECTED]> wrote: > Hi, > > I am currently developing a small Django application for my personal use. > Now I like to have a date based archive page, and I thought that this > finally is a good thing to look into generic views. My requirements are, > that I can display the actually database item on the page and in a side bar > a list of years, which link to year based archives, and a list of months in > the current year. From reading the documentation about generic views, I > think I have understood, that I can have either a list of years or a list of > months, but not both. Is this correct?
Well, the general operation of a generic view is to grab one "list" of things. Usually this is a list of items in a month, or items in a year, or items in a day, etc. However, you can pass extra information to the generic view with the 'extra_context' Take a look at this: http://awwca.ca/events/ Now, right now, there are no upcoming events, so it only shows all the past events. However, if there were upcoming events, they would be in the 'upcoming_events' variable in the context, passed to the template. You can take a look at the template code here: http://svn.jayparlar.com/website/trunk/awwca/templates/events/event_list.html And you can take a look at the urls.py that populates the context for the template here: http://svn.jayparlar.com/website/trunk/awwca/events/urls.py Also, if you want to have stuff in a sidebar, that's always there (no matter what page you're using), then you'd want something like template tags. Notice that on every page at awwca.ca, the right sidebar stuff is always there, and the information there is dynamic. Look at the "sidebar" div here: http://svn.jayparlar.com/website/trunk/awwca/templates/base.html, and notice that it does things like "{%random_thumbnail%}" and "{% upcoming_events %}" to populate the sidebar. > And besides generic views, I can also create the view myself. Is there a way > to select the years with entries from the database using the ORM? I can of > course use SQL, but I want to stick to the ORM and I want to learn a little > more about it, besides the basics I have used so far. Yep, the ORM can completely handle that. Check out the urls.py I pointed out above to see how I select upcoming events from the database, namely: def get_upcoming(): return Event.objects.filter(end_date__gte=datetime.now()).order_by('end_date') If you don't understand what's going on there, you'll need to read the documentation more. Hope this helps, Jay P. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---