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
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_
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
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
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):
...
?
--~--~-~--~~
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
6 matches
Mail list logo