Wednesday, October 30, 2013

Dynamic queries

Hi guys,

I would like to have dynamic query. For example i have a query like:

        rows_list = model_object.objects.not_deleted()
        query = Q(name__contains=search_term)
        query |= Q(equipment_manufacturer__name__contains=search_term)
        rows_list = rows_list.filter(query) 

I want to have name__contains dynamic.  

My idea to iterate trough model fields and create a query that will perform a search, so i can have one function that handles grid searching and search trough all the fields in given model. 

How can this be done?

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/b55695d9-854a-4eaf-b28b-81db4ea0aa22%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

No comments:

Post a Comment