> I suppose I could do something like r'^(?P<path>.*)$' and then parse path in 
> the view but this could wreak havoc with other URLs.

Yes, that's the way to do it. You can prevent it from clashing with
other URLs by prefixing it with something like categories/ so the URL
would be:

www.example.com/categories/category-1/category-2/

That being said, it's not entirely trivial to retrieve the nested
categories. I can think of 2 basic strategies:

1. Create a "path" field on the Category model that stores the full
path (category-1/category-2). This makes it very easy to find the
category:

Category.objects.get(path=path)

But this also means you have to build the path and store it every time
a category is saved, or one of its parent categories is saved.

2. Split apart the path (path.split("/")) then loop through each part,
and see if the category exists. In pseudocode, might look like this:

for part in path.split("/"):
  find category by part=part, parent=previous_part
  if not found, raise 404
  previous_part = part

This doesn't require any special code when saving a category, but
makes it a heck of a lot more difficult to retrieve a category.

Personally I'd go with the first option.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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.

Reply via email to