Many thanks to you both! That was enough info to get things working!
On Jul 7, 11:36 am, ringemup <ringe...@gmail.com> wrote: > Add a SlugField to the Page model, and populate it based on the title > (this can be done automatically either via the admin's > prepopulated_fields, or via a custom model save() method) > > class Page(models.Model): > title = models.CharField(max_length=50) > slug = models.SlugField() > > Then use a regex of the following form to pull the slug into your > view: > > (r'^(?P<unit_id>\d+)/(?P<page_slug>[\w-]+)/$', > 'project.app.views.unit_page'), > > Then in your view: > > def unit_page(request, unit_id, page_slug): > the_page = Page.objects.get(slug=PageSlug) > > Do the same for the Unit model and regex matching. Adjust as > necessary to fit your actual models. > > On Jul 7, 2:13 pm, Rodion Raskolnikiv <noah...@gmail.com> wrote: > > > > > To clarify, I would like to take the current url form of: > > > /dept_id/page_id/ (which looks like /2/13/) > > > into a url that looks like this: > > /accounting/policy_for_travel_expenses/ (which puts the title of the > > element in place of the element ID) > > > I am getting at the elements by ID this way: > > (r'^(?P<unit_id>\d+)/$', 'project.app.views.unit_index'), > > (r'^(?P<unit_id>\d+)/(?P<page_id>\d+)/$', > > 'project.app.views.unit_page'), > > > I am not sure how *[\w\d\-]+* would fit into my url configuration, I > > am still learning the very basics. > > > On Jul 7, 9:54 am, Daniel Lathrop <daniel.lath...@gmail.com> wrote: > > > > I'm not quite clear on what you're asking, but if the issue is how to > > > write > > > a regex for slugs: The regular expression you need for slugs is > > > *[\w\d\-]+* > > > > Hope that helps. > > > > Daniel > > > --------------------------- > > > Daniel Lathrop > > > > On Wed, Jul 7, 2010 at 9:32 AM, Rodion Raskolnikiv > > > <noah...@gmail.com>wrote: > > > > > Greetings! > > > > I am trying to implement a very simple (yet elegant) solution for a > > > > university departmental website in django. In designing my urls, I > > > > desired to have them follow this pattern: > > > > university.edu/department/page_title_made_into_slug > > > > > However, I couldn't get it working or find any doc that pointed out > > > > how to do it, so I temporarily settled for: > > > > univeristy.edu/1/14 (where 1 is the department ID and 14 is the > > > > page ID) > > > > > This is how I have my URLs set up right now: > > > > (r'^$', project.app.views.index'), > > > > (r'^(?P<unit_id>\d+)/$', 'project.app.views.unit_page'), > > > > > I have not actually set the pages to display yet, I thought that I > > > > would ask here before I did that ... > > > > > Could anyone direct me to a solution so that I could have my URLs the > > > > way that I want them? > > > > > -- > > > > 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<django-users%2bunsubscr...@google > > > > groups.com> > > > > . > > > > For more options, visit this group at > > > >http://groups.google.com/group/django-users?hl=en. -- 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.