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, childslug=None):
    if childslug:
        category = get_object_or_404(Category, slug=childslug)
    else:
        category = get_object_or_404(Category, slug=slug)
    ... rest of method as previous

This way, if you don't provide a childslug (as with the URLPattern
that only has one argument), the childslug will assume the default.

Another way that would work for your specific example would be to
simplify by just redefining your urlpatterns:

       (r'^category/[-\w]+/(?P<slug>[-\w]+)',
'entries_by_category'),
       (r'^category/(?P<slug>[-\w]+)', 'entries_by_category'),

This is only possible because your entries_by_child_category method
doesn't actually use childslug _AND_ slug. This urlpattern throws away
the parent slug, and can therefore use the same method definition for
both patterns.

Hope this helps,

Yours,
Russ Magee %-)

--~--~---------~--~----~------------~-------~--~----~
 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
-~----------~----~----~----~------~----~------~--~---

Reply via email to