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.
>
> How can this be done?

query = Q(**{'name_contains': search_term})

and so on.

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

No comments:

Post a Comment