mirror of
https://github.com/magnum-opus-tender-hack/backend.git
synced 2024-11-22 01:06:35 +03:00
updated search
This commit is contained in:
parent
ff57304ba2
commit
dbd347d71e
|
@ -1,13 +1,12 @@
|
|||
from django.db import models
|
||||
|
||||
# Create your models here.
|
||||
|
||||
|
||||
class Category(models.Model):
|
||||
name = models.CharField("Имя", unique=True, blank=False, max_length=250)
|
||||
value = models.CharField("Имя", unique=True, blank=False, max_length=250)
|
||||
|
||||
def __str__(self):
|
||||
return self.name
|
||||
return str(self.name)
|
||||
|
||||
class Meta:
|
||||
db_table = "Category"
|
||||
|
@ -18,13 +17,28 @@ class Product(models.Model):
|
|||
"ID CTE", primary_key=True, unique=True, blank=False, null=False, db_index=True
|
||||
)
|
||||
name = models.CharField("Название CTE", unique=True, blank=False, max_length=250)
|
||||
category = models.ForeignKey(
|
||||
Category, related_name="products", on_delete=models.CASCADE
|
||||
)
|
||||
characteristic = models.JSONField("Характеристики")
|
||||
|
||||
def __str__(self):
|
||||
return self.name
|
||||
return str(self.name)
|
||||
|
||||
def serialize_self(self) -> dict:
|
||||
return {
|
||||
'name': self.name,
|
||||
'characteristic': self.characteristic,
|
||||
}
|
||||
|
||||
class Meta:
|
||||
db_table = "Product"
|
||||
|
||||
|
||||
class ProductInCategory(models.Model):
|
||||
product = models.ForeignKey(
|
||||
Product, related_name="categories", on_delete=models.CASCADE
|
||||
)
|
||||
category = models.ForeignKey(
|
||||
Category, related_name="products", on_delete=models.CASCADE
|
||||
)
|
||||
|
||||
def __str__(self):
|
||||
return f"{self.product} in {self.category}"
|
||||
|
|
|
@ -1,2 +1,5 @@
|
|||
def process_string(text: str) -> dict:
|
||||
return {}
|
||||
from search.models import Product
|
||||
|
||||
|
||||
def process_string(text: str) -> [dict]:
|
||||
return [x.serialize_self() for x in Product.objects.filter(name__contains=text)[5:]]
|
||||
|
|
Loading…
Reference in New Issue
Block a user