Re: Need Help Thinking Through How to Setup URLS and VIEWS

2008-03-30 Thread Rob Hudson

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



Need Help Thinking Through How to Setup URLS and VIEWS

2008-03-29 Thread [EMAIL PROTECTED]

I am stuck trying to think through how to work something out. I want a
user to be able to create sections in an admin for a site. A user can
assign pages to a section. For instance, create the section About and
add the pages About Us and Contact and Staff.

That is all done. No problems. The part that is hard for me is
thinking through to Urls and Views.

This is kind of what makes sense to me:

If a slug contains just a page name... display the page detail. If a
slug contains a section name... display the section and any page
associated with it. Maybe a page list.. I have a different way to
designate the section homepage.

Anyways... I thought.. ooh, wrappers would work well here. What I need
is to create a wrapper that useses the generic.views.object_detail.
That is easy enough.

Problem is... how do I query other models based on many to many
relationships ... my head is swimming.

I realize this is alot. Can anyone suggest a direction to start
looking?

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