Re: Child Category Views

2006-11-09 Thread Jamie Pittock
Sorry, I missed those last two replies as I was replying myself. I'll take a look now and check I'm doing things right. Many thanks. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post t

Re: Child Category Views

2006-11-09 Thread Jamie Pittock
great. I'm sure it's not perfect yet but I ended up with this: def entries_by_category(request, slug, childslug=None): if childslug is not None: slug = childslug category = get_object_or_404(Category, slug=slug) entry_list_by_category = category.entry_set.order_by('-pub_

Re: Re: Child Category Views

2006-11-09 Thread Russell Keith-Magee
On 11/9/06, Jamie Pittock <[EMAIL PROTECTED]> wrote: > > I'm sure there must be a way of doing this with just the one view > though. There are multiple ways, depending on the exact result you want. One way is to define a view with a default argument: def entries_by_category(request, slug, child

Re: Child Category Views

2006-11-09 Thread ToddG
I think you can just use: def entries_by_category(request, slug, childslug=None) with your first urlpattern and then switch on childslug, i.e. if it's set or not. Also you're prob already looking at this but http://www.djangoproject.com/documentation/url_dispatch/#named-groups should help if

Re: Child Category Views

2006-11-09 Thread Jeremy Dunck
On 11/9/06, Jamie Pittock <[EMAIL PROTECTED]> wrote: > (r'^category/(?P[-\w]+)/(?P[-\w]+)', > 'entries_by_child_category'), How about: (r'^category/(?P[-\w]+)(/(?P[-\w]+))?/$', 'entries_by_category'), def entries_by_category(request, slug, childslug=None): ... ? --~--~-~--~~

Re: Child Category Views

2006-11-09 Thread Jamie Pittock
Sorry to reply to myself so quickly. After a bit of refactoring my two views look like this: def entries_by_category(request, slug): category = get_object_or_404(Category, slug=slug) entry_list_by_category = category.entry_set.order_by('-pub_date', 'title') return render

Child Category Views

2006-11-09 Thread Jamie Pittock
Hi folks, I've just started transporting an existing site to Django as a learning exercise and some quick help would be appreciated. I'm using some code from the cookbook to allow parent/child categories: http://code.djangoproject.com/wiki/CookBookCategoryDataModelPostMagic That's all dandy.