Thanks Karen. On Nov 19, 4:56 pm, Karen Tracey <kmtra...@gmail.com> wrote: > On Thu, Nov 19, 2009 at 7:25 PM, neridaj <neri...@gmail.com> wrote: > > Is it possible to pass vars to filters rather than hard coding the > > field name, something like this: > > > def search(request): > > query = request.GET.get('q', '') > > bits = request.GET.get('models', '').partition('.') > > model_name = bits[0] > > field_name = bits[2] > > model_type = ContentType.objects.get(app_label="blog", > > model=model_name) > > model_class = model_type.model_class() > > results = [] > > if query: > > results = model_class.objects.filter > > (field_name__icontains=query) > > return render_to_response('search/search.html', > > { 'query': query, 'results': > > results }) > > Create a dictionary of keyword arguments and pass that. For example: > > results = model_class.objects.filter(**{field_name+'__icontains': query}) > > Karen
-- 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=.