mirror of
https://github.com/magnum-opus-tender-hack/backend.git
synced 2024-11-22 09:16:36 +03:00
updated autocomplete, minor changes
This commit is contained in:
parent
acf568f207
commit
d74c515f4e
|
@ -1,3 +1,20 @@
|
|||
from django.contrib import admin
|
||||
|
||||
from search.models import (
|
||||
Characteristic,
|
||||
UnitCharacteristic,
|
||||
Category,
|
||||
Product,
|
||||
ProductCharacteristic,
|
||||
ProductUnitCharacteristic,
|
||||
)
|
||||
|
||||
# Register your models here.
|
||||
|
||||
|
||||
admin.site.register(Characteristic)
|
||||
admin.site.register(UnitCharacteristic)
|
||||
admin.site.register(Category)
|
||||
admin.site.register(Product)
|
||||
admin.site.register(ProductCharacteristic)
|
||||
admin.site.register(ProductUnitCharacteristic)
|
||||
|
|
18
app/search/migrations/0012_alter_product_name.py
Normal file
18
app/search/migrations/0012_alter_product_name.py
Normal file
|
@ -0,0 +1,18 @@
|
|||
# Generated by Django 4.0.8 on 2022-10-22 16:49
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('search', '0011_alter_product_options'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='product',
|
||||
name='name',
|
||||
field=models.TextField(verbose_name='Название CTE'),
|
||||
),
|
||||
]
|
|
@ -12,49 +12,67 @@ def autocomplete_schema(val: str, exclude: List[Dict]):
|
|||
schema.extend(
|
||||
[
|
||||
{
|
||||
"coordinate": cat["name"].replace("ё", "е").lower().index(val.lower()),
|
||||
"coordinate": cat["name"]
|
||||
.replace("ё", "е")
|
||||
.lower()
|
||||
.index(val.lower()),
|
||||
"value": {"type": "Category", "value": cat["name"]},
|
||||
}
|
||||
for cat in Category.objects.filter(name__unaccent__icontains=val)[
|
||||
:10
|
||||
].values("name")
|
||||
for cat in (
|
||||
Category.objects.filter(name__unaccent__istartswith=val)
|
||||
| Category.objects.filter(name__unaccent__icontains=val)
|
||||
)
|
||||
.distinct()[:10]
|
||||
.values("name")
|
||||
]
|
||||
)
|
||||
if not name_exclude:
|
||||
schema.extend(
|
||||
[
|
||||
{
|
||||
"coordinate": product["name"].replace("ё", "е").lower().index(val.lower()),
|
||||
"coordinate": product["name"]
|
||||
.replace("ё", "е")
|
||||
.lower()
|
||||
.index(val.lower()),
|
||||
"value": {
|
||||
"type": "Name",
|
||||
"value": product["name"],
|
||||
},
|
||||
}
|
||||
for product in Product.objects.filter(name__unaccent__icontains=val)[
|
||||
:30
|
||||
].values("name")
|
||||
for product in (
|
||||
Product.objects.filter(name__unaccent__istartswith=val)
|
||||
| Product.objects.filter(name__unaccent__icontains=val)
|
||||
)
|
||||
.distinct()[:30]
|
||||
.values("name")
|
||||
]
|
||||
)
|
||||
schema.extend(
|
||||
[
|
||||
{
|
||||
"coordinate": char["value"].replace("ё", "е").lower().index(val.lower()),
|
||||
"coordinate": char["value"]
|
||||
.replace("ё", "е")
|
||||
.lower()
|
||||
.index(val.lower()),
|
||||
"value": {"type": char["name"], "value": char["value"]},
|
||||
}
|
||||
for char in Characteristic.objects.filter(value__unaccent__icontains=val)[
|
||||
:20
|
||||
].values("name", "value")
|
||||
for char in (
|
||||
Characteristic.objects.filter(value__unaccent__istartswith=val)
|
||||
| Characteristic.objects.filter(value__unaccent__icontains=val)
|
||||
)
|
||||
.distinct()[:20]
|
||||
.values("name", "value")
|
||||
]
|
||||
)
|
||||
schema.extend(
|
||||
[
|
||||
{
|
||||
"coordinate": char["name"].lower().replace("ё", "е").index(val.lower()),
|
||||
"value": {
|
||||
"type": char["name"] + "_numeric",
|
||||
"value": char["name"]
|
||||
}
|
||||
} for char in UnitCharacteristic.objects.filter(name__unaccent__icontains=val)[:20].values("name", "value")
|
||||
"value": {"type": char["name"] + "_numeric", "value": char["name"]},
|
||||
}
|
||||
for char in UnitCharacteristic.objects.filter(
|
||||
name__unaccent__icontains=val
|
||||
)[:20].values("name", "value")
|
||||
]
|
||||
)
|
||||
return schema
|
||||
|
|
|
@ -1,3 +0,0 @@
|
|||
from django.test import TestCase
|
||||
|
||||
# Create your tests here.
|
|
@ -1,3 +0,0 @@
|
|||
from django.shortcuts import render
|
||||
|
||||
# Create your views here.
|
Loading…
Reference in New Issue
Block a user