Django_autocomplete v2 search several database fields but only show choices where text is found

15 views
Skip to first unread message

Toni Schoenbuchner

unread,
Feb 22, 2017, 9:39:01 AM2/22/17
to yourlabs
Hi there,

I´m having trouble getting following to work:

My autocomplete is registered with search fields for ResourceBaseMode: title, abstract and purpose.
autocomplete_light.register(ResourceBase,
    search_fields
=['title','abstract', 'purpose'],
    autocomplete_js_attributes
={'placeholder': 'Resource name..', },)

https://github.com/GeoNode/geonode/blob/2.4.x/geonode/base/autocomplete_light_registry.py#L11

The results from ResourceBaseModel  are returned here:
def __unicode__(self):
   
return self.
title

Further the js configuration of the input can be seen here. 

What changes are needed to show choices in search input with all 3 search fields but only when the given string is found in a certain field.
Here an example to make it more clear:

1. Database table:
id   |   title   |  abstract  |  purpose
1    |  dog 1    |  her dog   |  love other dogs  
2    |  dog 2    |your friend |  is a good dog
3    |  cat 1    |  my cat    |  hates dogs  
4    |  cat 2    |  your cat  |  always sleeps  


2. User input: dog

3. Expected choices in autocomplete:
dog 1, her dog, love other dogs  
dog 2, is a good dog
hates
dogs  

I have a good understanding for mvc but a novice with Django.

Thank you!




Reply all
Reply to author
Forward
0 new messages