def get_queryset(self): purpose = self.forwarded.get('purpose') skin_type = self.forwarded.get('skin_type') category = self.forwarded.get('category') if purpose or skin_type or category: data = {} if purpose: data.update({'purpose': purpose}) if skin_type: data.update({'skin_type': skin_type}) if category: data.update({'category': category}) qs = PremiumProduct.search_fit(**data) else: qs = PremiumProduct.objects.all() qs = qs.order_by('brand__name_en', 'name_cn') if include_non_asc(self.q): qs = qs.filter( Q(name_cn__icontains=self.q) | Q(brand__name_cn__icontains=self.q) | Q(alias__icontains=self.q)) else: # all ascii, number and letter key = self.q.lower() qs = qs.filter( Q(pinyin__contains=key) | Q(name_cn__icontains=key) | Q(name_en__icontains=key) | Q(brand__name_en__icontains=key)) return qs
def get_queryset(self): # order by carrier usage qs = ExpressCarrier.objects.all() if include_non_asc(self.q): qs = qs.filter(Q(name_cn__icontains=self.q)) else: # all ascii, number and letter qs = qs.filter(pinyin__contains=self.q.lower()) return qs
def get_condition(self, keyword): if include_non_asc(keyword): return Q(name_cn__icontains=keyword) | Q( brand__name_cn__icontains=keyword) else: # all ascii, number and letter keyword = keyword.lower() return Q(pinyin__contains=keyword) | Q( name_en__icontains=keyword) | Q( brand__name_en__icontains=keyword)
def get_queryset(self): qs = Brand.objects.all() if include_non_asc(self.q): qs = qs.filter(name_cn__icontains=self.q) else: # all ascii, number and letter key = self.q.lower() qs = qs.filter( Q(pinyin__icontains=key) | Q(name_en__icontains=key) | Q(name_cn__icontains=key)) return qs
def get_queryset(self): qs = Customer.objects.order_by('-order_count') if include_non_asc(self.q): qs = qs.filter(name__icontains=self.q) else: # all ascii, number and letter if self.q.isdigit(): qs = qs.filter(mobile__icontains=self.q) else: qs = qs.filter(pinyin__contains=self.q.lower()) return qs
def get_queryset(self): qs = Address.objects.all() cid = self.forwarded.get('customer') if cid: qs = qs.filter(customer_id=cid) if include_non_asc(self.q): qs = qs.filter( Q(name__icontains=self.q) | Q(address__icontains=self.q)) else: # all ascii, number and letter if self.q.isdigit(): qs = qs.filter(mobile__icontains=self.q) else: qs = qs.filter(pinyin__contains=self.q.lower()) return qs
def create_object(self, text): if '@' in text: brand_name = text.split('@')[0] product_name = text[text.index('@') + 1:] brand = self.get_or_create_brand(brand_name) if include_non_asc(product_name): product, created = Product.objects.get_or_create( brand=brand, name_cn=product_name, seller=self.request.profile) else: product, created = Product.objects.get_or_create( brand=brand, name_en=product_name, seller=self.request.profile) return product return self.get_queryset().create(**{ self.create_field: text, 'seller': self.request.profile })
def get_queryset(self): qs = Product.objects.all() brand_id = self.request.GET.get('brand_id', '') category = self.forwarded.get('category') or self.request.GET.get( 'category', '') if brand_id: qs = qs.filter(brand__id=brand_id) if category: qs = qs.filter(category=category) if include_non_asc(self.q): qs = qs.filter( Q(name_cn__icontains=self.q) | Q(brand__name_cn__icontains=self.q) | Q(alias__icontains=self.q)) else: # all ascii, number and letter key = self.q.lower() if key: qs = qs.filter( Q(pinyin__icontains=key) | Q(name_en__icontains=key) | Q(name_cn__icontains=key)) return qs
def get_or_create_brand(self, brand_name): if include_non_asc(brand_name): brand, created = Brand.objects.get_or_create(name_cn=brand_name) else: brand, created = Brand.objects.get_or_create(name_en=brand_name) return brand