#2544: Pass variables from url handler to the query set of a generic view ---------------------------------+------------------------------------------ Reporter: [EMAIL PROTECTED] | Owner: jacob Type: enhancement | Status: new Priority: normal | Milestone: Component: Generic views | Version: Severity: normal | Resolution: Keywords: | ---------------------------------+------------------------------------------ Old description:
> If would be nice if you could pass variables from the url regexp in > urls.py to the filter of a query set when using generic views. > > {{{(r'^/?(?P<person>\w+)/$', > 'django.views.generic.list_detail.object_list', {'queryset': > Item.objects.filter(name__name__iexact=person))}}} > > Currently, a statement similar to the following will fail with a > NameError similar to the below: > > {{{NameError at /dave/ > name 'person' is not defined > Request Method: GET > Request URL: http://localhost:8000/dave/ > Exception Type: NameError > Exception Value: name 'dave' is not defined}}} > > The ideal behaviour would be that the filter function would be able to > accept values from the url dispatcher. > > This ticket arises from [[http://groups.google.com/group/django- > users/browse_thread/thread/40c34ae87492d4dd/67cabff7abbbabe5#67cabff7abbbabe5 > this]] discussion on django-users. New description: If would be nice if you could pass variables from the url regexp in urls.py to the filter of a query set when using generic views. {{{(r'^/?(?P<person>\w+)/$', 'django.views.generic.list_detail.object_list', {'queryset': Item.objects.filter(name__name__iexact=person))}}} Currently, a statement similar to the following will fail with a NameError similar to the below: {{{ NameError at /dave/ name 'person' is not defined Request Method: GET Request URL: http://localhost:8000/dave/ Exception Type: NameError Exception Value: name 'dave' is not defined }}} The ideal behaviour would be that the filter function would be able to accept values from the url dispatcher. This ticket arises from [[http://groups.google.com/group/django- users/browse_thread/thread/40c34ae87492d4dd/67cabff7abbbabe5#67cabff7abbbabe5 this]] discussion on django-users. Comment (by adrian): Maybe this? {{{ #!python queryset_func = lambda kwargs: Item.objects.filter(name__name__iexact=kwargs['person']) (r'^/?(?P<person>\w+)/$', 'django.views.generic.list_detail.object_list', {'queryset_func': queryset_func}) }}} The generic view would call {{{queryset_func(kwargs)}}} at runtime, with {{{kwargs}}} being the dictionary of parameters captured from the URL. -- Ticket URL: <http://code.djangoproject.com/ticket/2544> Django <http://code.djangoproject.org/> The web framework for perfectionists with deadlines. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django updates" group. To post to this group, send email to django-updates@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-updates -~----------~----~----~----~------~----~------~--~---