backend/app/search/services/autocomplete_schema.py

39 lines
1.0 KiB
Python
Raw Normal View History

2022-10-22 03:09:14 +03:00
from search.models import Product, Category, Characteristic
2022-10-22 05:07:25 +03:00
2022-10-22 03:09:14 +03:00
def autocomplete_schema(val: str):
schema = []
schema.extend(
[
{
2022-10-22 05:07:25 +03:00
"coordinate": product["name"].index(val),
"value": {
"type": "Name",
"value": product["name"],
},
}
for product in Product.objects.filter(name__contains=val).values("name")
]
2022-10-22 03:09:14 +03:00
)
schema.extend(
[
{
2022-10-22 05:07:25 +03:00
"coordinate": cat["name"].index(val),
"value": {"type": "Category", "value": cat["name"]},
}
for cat in Category.objects.filter(name__contains=val).values("name")
2022-10-22 03:09:14 +03:00
]
)
schema.extend(
[
{
2022-10-22 05:07:25 +03:00
"coordinate": char.name.index(val),
"value": {"type": char.name, "value": char.value},
}
for char in Characteristic.objects.filter(name__contains=val).values(
"name", "value"
)
2022-10-22 03:09:14 +03:00
]
)
return schema