summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaul Eggleton <paul.eggleton@linux.intel.com>2017-10-31 08:37:25 +1300
committerPaul Eggleton <paul.eggleton@linux.intel.com>2017-10-31 09:58:30 +1300
commit44386eea41a8e1bb8a3ab831613cfc1a19ff6ecd (patch)
tree52624be126b01823666f5478a22bd7ded11a2bb7
parentbe95164aa7ca220dcfb624a464f95077a49582c1 (diff)
downloadopenembedded-core-contrib-44386eea41a8e1bb8a3ab831613cfc1a19ff6ecd.tar.gz
querysethelper: fix searching
Don't assume that every model will have a "search_allowed_fields" attribute - if it doesn't, default to all CharFields in the model. This fixes searching via the REST API. Signed-off-by: Paul Eggleton <paul.eggleton@linux.intel.com>
-rw-r--r--layerindex/querysethelper.py8
1 files changed, 6 insertions, 2 deletions
diff --git a/layerindex/querysethelper.py b/layerindex/querysethelper.py
index 6c8daa41b5..b4d30c20e9 100644
--- a/layerindex/querysethelper.py
+++ b/layerindex/querysethelper.py
@@ -1,6 +1,6 @@
import operator
import functools
-from django.db.models import Q
+from django.db.models import Q, CharField
def _verify_parameters(g, mandatory_parameters):
miss = []
@@ -79,8 +79,12 @@ def _validate_input(input, model):
def _get_search_results(search_term, queryset, model):
search_objects = []
for st in search_term.split(" "):
+ if hasattr(model, 'search_allowed_fields'):
+ fieldlist = model.search_allowed_fields
+ else:
+ fieldlist = [f.name for f in model._meta.get_fields() if isinstance(f, CharField)]
q_map = map(lambda x: Q(**{x+'__icontains': st}),
- model.search_allowed_fields)
+ fieldlist)
search_objects.append(functools.reduce(operator.or_, q_map))
search_object = functools.reduce(operator.and_, search_objects)