On Jan 24, 11:23 pm, mehdi0016 <[email protected]> wrote:
> but in my dynamic field searching issue, exact field name used by
> filter method. even dictionary of fields not help there.
>
> tables = {"Author": Author, "Book": Book,}
> fields = {"Author":Author().first_name, "Book":Book().title}
>
> if requst.GET['table']  in tables:
>    f = fields[requst.GET['field']]
>    matches = tables[requst.GET['table']].objects.filter
> (f__icontains=requst.GET['query'])
>
> thanks, Mehdi.
>

in python you can pass functions arguments as a dictionary:

 tables = {"Author": Author, "Book": Book,}

 if request.GET['table']  in tables:
    table = tables[request.GET['table']]
    field = request.GET['field']
    query = request.GET['field']
    filterargs = { field: query, }
    matches = table.objects.filter(**filterargs)

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to