autcomplete

This commit is contained in:
ilia 2022-10-22 19:55:05 +03:00
parent da2b9e16d4
commit ed2a60b481

View File

@ -1,6 +1,6 @@
from typing import List, Dict
from search.models import Product, Category, Characteristic
from search.models import Product, Category, Characteristic, UnitCharacteristic
def autocomplete_schema(val: str, exclude: List[Dict]):
@ -46,4 +46,15 @@ def autocomplete_schema(val: str, exclude: List[Dict]):
].values("name", "value")
]
)
schema.extend(
[
{
"coordinate": char["value"].lower().index(val.lower()),
"value": {
"type": char["name"] + "_numeric",
"value": char["value"]
}
} for char in UnitCharacteristic.objects.filter(value__unaccent__icontains=val)[:20].values("name", "value")
]
)
return schema