history admin dropdown for admin

This commit is contained in:
Sam
2021-03-10 11:52:43 +00:00
parent d01d5bf407
commit 39c8bd5e44
4 changed files with 14 additions and 65 deletions

View File

@@ -73,7 +73,10 @@ class City(models.Model):
updated = models.DateTimeField('date last update', auto_now=True) updated = models.DateTimeField('date last update', auto_now=True)
def __str__(self): def __str__(self):
return f'{self.name} [{self.province}]' if self.province:
return f'{self.name} [{self.province}]'
else:
return f'{self.name}'
class Meta: class Meta:
verbose_name = "Municipio" verbose_name = "Municipio"

View File

@@ -1,12 +1,16 @@
from django.contrib import admin from django.contrib import admin
from django_admin_listfilter_dropdown.filters import RelatedDropdownFilter, ChoiceDropdownFilter
from . import models from . import models
# Register your models here. # Register your models here.
class HistoryAdmin(admin.ModelAdmin): class HistoryAdmin(admin.ModelAdmin):
list_display = ('company_name', 'rss_url', 'sync_date', 'result', 'quantity',) list_display = ('company_name', 'rss_url', 'sync_date', 'result', 'quantity',)
list_filter = ('company__company_name',) list_filter = (
('company', RelatedDropdownFilter),
)
def company_name(self, instance): def company_name(self, instance):
if instance.company and instance.company.company_name: if instance.company and instance.company.company_name:

View File

@@ -14,7 +14,6 @@ from rest_framework import status
from companies.factories import CompanyFactory from companies.factories import CompanyFactory
from products.factories import ProductFactory, ActiveProductFactory from products.factories import ProductFactory, ActiveProductFactory
from products.models import Product from products.models import Product
# from products.utils import find_related_products_v3
from core.factories import CustomUserFactory from core.factories import CustomUserFactory
from core.utils import get_tokens_for_user from core.utils import get_tokens_for_user
@@ -1159,45 +1158,6 @@ class AdminProductViewSetTest(APITestCase):
self.assertEquals(response.status_code, 204) self.assertEquals(response.status_code, 204)
'''
class FindRelatedProductsTest(APITestCase):
def setUp(self):
"""Tests setup
"""
self.factory = ActiveProductFactory
self.model = Product
# clear table
self.model.objects.all().delete()
def test_v3_find_by_tags(self):
# create tagged product
tag = 'cool'
expected_instances = [
self.factory(tags=tag),
self.factory(tags=f'{tag} hat'),
self.factory(tags=f'temperatures/{tag}'),
self.factory(tags=f'temperatures/{tag}, body/hot'),
self.factory(tags=f'temperatures/{tag}, hats/{tag}'),
# multiple hits
self.factory(tags=tag, attributes=tag),
self.factory(tags=tag, attributes=tag, category=tag),
self.factory(tags=tag, attributes=tag, category=tag, name=tag),
self.factory(tags=tag, attributes=tag, category=tag, name=tag, description=tag),
]
unexpected_instances = [
self.factory(tags="notcool"), # shouldn't catch it
self.factory(tags="azules"),
]
# searh for it
results = find_related_products_v3(tag)
# assert result
self.assertTrue(len(results) == len(expected_instances))
'''
class PurchaseEmailTest(APITestCase): class PurchaseEmailTest(APITestCase):
def setUp(self): def setUp(self):

View File

@@ -87,31 +87,13 @@ def extract_search_filters(result_set):
def get_related_products(description, tags, attributes, category): def get_related_products(description, tags, attributes, category):
products_qs = Product.objects.filter( products_qs = Product.objects.filter(
description=description, Q(description=description) |
tags__in=tags, Q(tags__in=tags) |
attributes__in=attributes, Q(attributes__in=attributes) |
category=category Q(category=category)
)[:6] )[:10]
return products_qs return products_qs
'''
def find_related_products_v3(keyword):
"""
Ranked product search
SearchVectors for the fields
SearchQuery for the value
SearchRank for relevancy scoring and ranking
"""
vector = SearchVector('name') + SearchVector('description') + SearchVector('tags__label') + SearchVector('attributes__label') + SearchVector('category__name')
query = SearchQuery(keyword)
products_qs = Product.objects.annotate(
rank=SearchRank(vector, query)
).filter(rank__gt=0.05) # removed order_by because its lost in casting
return set(products_qs)
'''
def ranked_product_search(keyword, shipping_cost=None, discount=None, category=None, tags=None, price_min=None,price_max=None): def ranked_product_search(keyword, shipping_cost=None, discount=None, category=None, tags=None, price_min=None,price_max=None):
""" """