Pass a captured named regular expression to URL dictionary in generic view
Posted
by Trent Jurewicz
on Stack Overflow
See other posts from Stack Overflow
or by Trent Jurewicz
Published on 2010-04-22T03:36:42Z
Indexed on
2010/04/22
3:43 UTC
Read the original article
Hit count: 277
django-urls
I am working with a generic view in Django. I want to capture a named group parameter in the URL and pass the value to the URL pattern dictionary. For example, in the URLConf below, I want to capture the parent_slug
value in the URL and pass it to the queryset dictionary value like so:
urlpatterns = patterns('django.views.generic.list_detail',
(r'^(?P<parent_slugs>[-\w])$', 'object_list', {'queryset':Promotion.objects.filter(category=parent_slug)}, 'promo_promotion_list'),
)
Is this possible to do in one URLConf entry, or would it be wiser if I create a custom view to capture the value and pass the queryset directly to the generic view from my overridden view?
© Stack Overflow or respective owner