Wednesday, December 7, 2011

URL Issue - Slugged Url with Custom IDs

Hi all -

Question. I would love to use a slug in the usual way for nice urls:

#urls.py
urlpatterns = patterns('app.views',
(r'^(?P<myslug>.*)/foo/$', 'viewfunction'),
)

#views.py
def viewfunction(request, myslug):
themodel = get_object_or_404(MyModel, slug=myslug)

However, due to requirements 'themodel' will have to be pulled by a
custom id that is retrieved via an API. From there to get proper
routing I had to chang urls.py and views.py to.

#urls.py
urlpatterns = patterns('app.views',
(r'^(?P<api_id>.*)/foo/$', 'viewfunction'),
)

#views.py
def viewfunction(request, api_id):
themodel = get_object_or_404(MyModel, custom_id=api_id)

This works. But with ugly URLS:

What is the cleanest way to pull mymodel with the custom api_id, and
still have a slug/seo friendly url?

This seems simple but my mind is trying to make it complex.

Thanks,
Matt

--
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+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate