On Mar 29, 2:54 pm, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]>
wrote:
> Specifically, i need help with:
> 1. How do I test to see what a slug is? I.E. In my case, is it a
> section or a page.
>
> Finally, am I barking up the wrong tree? Would it be simpler to just
> write a custom view that does what I want? Any advice is much
> appreciated.

I think the flow could go something like the following.  I'm guessing
that it makes sense to check the Section slug before the Page slug but
that could easily be reversed...

def section_or_page(request, slug):
    # Look for section and call section_detail if found
    try:
        section = Section.objects.get(slug=slug)
    except Section.DoesNotExist:
        pass # Check for page down below
    else:
        return section_detail(request, section) # another view
    # Look for page and call page_detail if found
    try:
        page = Page.objects.get(slug=slug)
    except Page.DoesNotExist:
        pass # return 404 below
    else:
        return page_detail(request, page)
    # Otherwise, return 404
    raise Http404, "No page or section found matching the slug: %s" %
(slug)

Then your detail views can do what you'd normally do, for example:

def section_detail(request, section):
    # get other pieces from other models?
    return render_to_response('section/blah.html', {'section':
section, 'other': other_model},
context_instance=RequestContext(request))

Hope that helps,
Rob
--~--~---------~--~----~------------~-------~--~----~
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