Лучшим способом было бы разделить его на представление:
r'^(?P<model>[a-zA-Z0-9_-]+)/(?P<slug>[a-zA-Z0-9_-]+)/$', 'some_detail')
и представление:
def some_detail(request, model, slug):
try:
model = {'book':Book, 'author':Author}[model]
except KeyError:
raise Http404
item = get_object_or_404(model, slug=slug)
do_something_with(item)
...
edit: О, плоский как этот ... это было бы:
(r'^(?P<slug>[a-zA-Z0-9_-]+)/$', 'universal_detail'),
def universal_detail(request, slug):
try:
book = Book.objects.get(slug=slug)
return book_detail(request, book)
except Book.DoesNotExist:
pass
try:
author = Author.objects.get(slug=slug)
return author_details(request, author)
except Author.DoesNotExist:
raise Http404
def book_detail(request, book):
# note that book is a book instance here
pass