add basic product search
This commit is contained in:
84
products/models.py
Normal file
84
products/models.py
Normal file
@ -0,0 +1,84 @@
|
||||
import logging
|
||||
import re
|
||||
|
||||
from django.conf import settings
|
||||
from django.db import models
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class Product(models.Model):
|
||||
sap_id_regex = r'\b(\d{7})\b'
|
||||
sap = models.CharField(max_length=10, db_column='sap_article_number')
|
||||
name = models.CharField(max_length=100, db_column='short_name')
|
||||
model = models.CharField(max_length=100, db_column='model')
|
||||
family = models.CharField(max_length=100, db_column='product_family')
|
||||
color = models.CharField(max_length=100, db_column='color')
|
||||
|
||||
class Meta:
|
||||
managed = False
|
||||
db_table = "adilog_product"
|
||||
|
||||
@staticmethod
|
||||
def find_sap_ids(text):
|
||||
matches = re.finditer(Product.sap_id_regex, text)
|
||||
return [match.group(1) for match in matches]
|
||||
|
||||
def serialize(self):
|
||||
return {
|
||||
'id': self.sap,
|
||||
'name': self.name,
|
||||
'model': self.model,
|
||||
'family': self.family,
|
||||
'color': self.color,
|
||||
}
|
||||
|
||||
|
||||
"""
|
||||
create view adilog_product as
|
||||
SELECT DISTINCT ks.style AS id, ks.sap_article_number,
|
||||
(((kr.ranksection || '-'::text) || kr.rankcategory) || '-'::text) || kr.modelrank
|
||||
AS grouping_number,
|
||||
km.name AS short_name, kr.model, kr.color,
|
||||
kr.category AS product_type, km.category AS model_product_type,
|
||||
kr.men_women AS gender, kr.segmentation AS segment, ks.color_name AS colorway,
|
||||
km.summary AS blurb, km.description,
|
||||
km.tech_icon_1, km.tech_icon_2, km.tech_icon_3, km.tech_icon_4,
|
||||
km.tech_icon_5, km.tech_icon_6, km.tech_icon_7, km.tech_icon_8,
|
||||
km.tech_icon_9, km.tech_icon_10, km.tech_icon_11, km.tech_icon_12,
|
||||
km.tech_icon_13, km.tech_icon_14, km.tech_icon_15,
|
||||
km.sizing AS size,
|
||||
km.tech_call_out_1 AS point0, km.tech_call_out_2 AS point1,
|
||||
km.tech_call_out_3 AS point2, km.tech_call_out_4 AS point3,
|
||||
km.tech_call_out_5 AS point4, km.tech_call_out_6 AS point5,
|
||||
km.tech_call_out_7 AS point6, km.tech_call_out_8 AS point7,
|
||||
km.tech_call_out_9 AS point8, km.tech_call_out_10 AS point9,
|
||||
km.tech_call_out_11 AS point10, km.tech_call_out_12 AS point11,
|
||||
km.tech_call_out_13 AS point12, km.tech_call_out_14 AS point13,
|
||||
km.tech_call_out_15 AS point14, km.tech_call_out_16 AS point15,
|
||||
km.tech_call_out_17 AS point16, km.tech_call_out_18 AS point17,
|
||||
km.tech_call_out_19 AS point18, km.tech_call_out_20 AS point19,
|
||||
kr.modelstatus, kr.stylestatus, kr.hero, kr.alt_hero, ks.hero AS stylehero,
|
||||
kr.stylerank, km.relatedkidsmodel1, km.relatedkidsmodel2,
|
||||
km.dimensions, km.height, km.weight, km.capacity, km.origin, km.fiber,
|
||||
km.upper, km.lining, km.tooling, kr.in_current_season, km.imageistall,
|
||||
km.retail, km.wholesale, kr.country, kr.pagination, km.legal, -- km.legal2,
|
||||
km.duty_type,
|
||||
km.heavy_metal_fabrication,
|
||||
km.masonry,
|
||||
km.energy,
|
||||
km.construction,
|
||||
km.utilities,
|
||||
km.landscaping,
|
||||
km.transportation,
|
||||
km.maintenance,
|
||||
km.manufacturing,
|
||||
km.warehouse_distribution,
|
||||
km.service,
|
||||
-- km.public_safety_duty,
|
||||
km.extra_1, km.extra_2, km.extra_3, km.extra_4, km.extra_5, km.extra_6,
|
||||
km.product_family
|
||||
FROM keen_ranking kr
|
||||
JOIN keen_style ks ON kr.style = ks.sap_article_number
|
||||
JOIN keen_model km ON kr.model = km.model;
|
||||
"""
|
||||
Reference in New Issue
Block a user