Wednesday, October 30, 2013

Re: Dynamic queries

On Wed, Oct 30, 2013 at 1:25 PM, Domagoj Kovač <doctorkovac@gmail.com> wrote:
> 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.
>

Further to my earlier answer, you can use that technique to easily
build up dynamic queries, but I'd question the value if you have more
than a few model instances, or many attributes to search. If you
really want to search all fields, use haystack with a solr backend.

Cheers

Tom

--
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/CAFHbX1LYH72JhGGcEW69CEPC54nE9mzZFb_Fkth842_oFL%3Dtjg%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.

No comments:

Post a Comment