On 8 avr, 16:37, Alastair Campbell <ala...@gmail.com> wrote: > Hi, > > Hopefully a newbie question with an easy answer? > > I have a site with various modules (news, events, pictures galleries > etc.), but I would like the site to be structured by categories rather > than function. > > It's a windsurfing site, so the categories are race, wave, freestyle, etc. > > In my URLs, how would I get it to filter various apps by discipline so > that you have: > /freestyle/news/ > /freestyle/galleries/ > /racing/news/ > /racing/galleries/ > etc. > > Without creating a huge set of URL patterns?
At the url level, it's no big deal: url(r'(?P<category_slug>[a-z-]+)/news/$', "news.views.by_category"), url(r'(?P<category_slug>[a-z-]+)/galleries/$', "galleries.views.by_category"), etc... Now you need to write the relevant views, and of course tie all your news / galleries / whatever contents to categories. Note that if your project is well designed, the dependancies between categories and contents should be inverted so categories knows about contents, not the other way round. In this case, you could as well have a generic "content_type_by_category(request, ct_name, category_slug)" view, and one single url pattern: url(r'(?P<category_slug>[a-z-]+)/(?P<ct_name>[a-z]+)/$', "categories.views.content_type_by_category") These are of course Q&D examples - as we don't know what your apps / project look like. > Is there a pattern matching approach for this sort of thing, or is it > always done by function? url resolution in Django is only patterns to views mapping, and if some app doesn't provide the appropriate view function nothing prevents you from writing it yourself. Just make sure your patterns dont overlap or are in the correct order. NB : one of the first things I usually do when starting a new django project is to create a project-specific app where I can put all the code that's specific to the project (templatetags, urls, custom views etc). -- 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 django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.