From a5b90c2dcdd08a48cdd2cc633c0344b31f5b8bde Mon Sep 17 00:00:00 2001 From: Ruslan Atarov Date: Thu, 7 Dec 2023 15:10:35 +0300 Subject: [PATCH 1/2] readme --- README.md | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 586430e..d8c34e7 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ http://81.31.246.5/
email: admin@admin.admin password: Password-123 ``` -## Архивы и фото +## Архивы и фото приложения Вставить сюда фотки с сайта ## FRONTEND: @@ -19,12 +19,19 @@ https://github.com/hackathone-prosept-team2/data-science ![image](https://img.shields.io/badge/Python%203.11-FFD43B?style=for-the-badge&logo=python&logoColor=blue) ![image](https://img.shields.io/badge/Django%204.2-092E20?style=for-the-badge&logo=django&logoColor=green) ![image](https://img.shields.io/badge/django%20rest%203.14-ff1709?style=for-the-badge&logo=django&logoColor=white) +![image](https://img.shields.io/badge/DRF_Spectacular-aa1000?style=for-the-badge&logo=django&logoColor=white) ![image](https://img.shields.io/badge/PostgreSQL-316192?style=for-the-badge&logo=postgresql&logoColor=white) ![image](https://img.shields.io/badge/Docker-2CA5E0?style=for-the-badge&logo=docker&logoColor=white) ![image](https://img.shields.io/badge/Nginx-009639?style=for-the-badge&logo=nginx&logoColor=white) ![image](https://img.shields.io/badge/GitHub-100000?style=for-the-badge&logo=github&logoColor=white) ![image](https://img.shields.io/badge/GitHub_Actions-2088FF?style=for-the-badge&logo=github-actions&logoColor=white) +![image](https://img.shields.io/badge/Poetry-053766?style=for-the-badge&logo=Sailfish%20OS&logoColor=white) ![image](https://img.shields.io/badge/Pytest-86D46B?style=for-the-badge&logo=redux%20saga&logoColor=999999) ++ DS-сервис рекомендаций: +![image](https://img.shields.io/badge/Pandas-2C2D72?style=for-the-badge&logo=pandas&logoColor=white) +![image](https://img.shields.io/badge/NLTK-FF3621?style=for-the-badge) +![image](https://img.shields.io/badge/SKlearn-7A1FA2?style=for-the-badge) + ### Доступ в админ-панель: http://81.31.246.5/admin From 88558cf221c43338602cf5e150133e0f33f59a0a Mon Sep 17 00:00:00 2001 From: Ruslan Atarov Date: Thu, 7 Dec 2023 15:23:48 +0300 Subject: [PATCH 2/2] added url to dealer_key --- apps/api/v1/dealers/serializer.py | 2 ++ apps/dealers/admin.py | 4 ++-- apps/dealers/crud.py | 22 ++++++++++++++++++++++ 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/apps/api/v1/dealers/serializer.py b/apps/api/v1/dealers/serializer.py index fb4ceb1..54772c0 100644 --- a/apps/api/v1/dealers/serializer.py +++ b/apps/api/v1/dealers/serializer.py @@ -80,6 +80,7 @@ class KeySerializer(BaseKeySerializer): name = serializers.CharField() last_price = serializers.DecimalField(max_digits=7, decimal_places=2) status = serializers.SerializerMethodField() + url = serializers.CharField() class Meta(BaseKeySerializer.Meta): model = DealerKey @@ -87,6 +88,7 @@ class Meta(BaseKeySerializer.Meta): "name", "last_price", "status", + "url", ) def get_status(self, obj): diff --git a/apps/dealers/admin.py b/apps/dealers/admin.py index 5f16f45..68de252 100644 --- a/apps/dealers/admin.py +++ b/apps/dealers/admin.py @@ -3,7 +3,7 @@ from django.db.models.query import QuerySet from django.http.request import HttpRequest -from .crud import list_keys +from .crud import list_keys_in_admin from .models import Dealer, DealerKey, Match @@ -47,7 +47,7 @@ class DealerKeyAdmin(admin.ModelAdmin): empty_value_display = "-пусто-" def get_queryset(self, request: HttpRequest) -> QuerySet[Any]: - return list_keys() + return list_keys_in_admin() def name(self, obj): return obj.name diff --git a/apps/dealers/crud.py b/apps/dealers/crud.py index fb2bb1c..abc5b21 100644 --- a/apps/dealers/crud.py +++ b/apps/dealers/crud.py @@ -55,6 +55,11 @@ def list_keys() -> QuerySet[DealerKey]: "price" )[:1] ), + url=Subquery( + DealerPrice.objects.filter(key_id=OuterRef("pk")).values( + "product_url" + )[:1] + ), declined=Count( "matches", filter=Q(matches__status=Match.MatchStatus.NO) ), @@ -64,6 +69,23 @@ def list_keys() -> QuerySet[DealerKey]: ) +def list_keys_in_admin() -> QuerySet[DealerKey]: + """Получение списка ключей/артикулов дилеров для админ-панели.""" + return ( + DealerKey.objects.select_related("dealer", "product") + .prefetch_related("matches") + .annotate( + name=Subquery( + DealerPrice.objects.filter(key_id=OuterRef("pk")).values( + "name" + )[:1] + ), + ) + # фильтр позволяет выгружать только ключи, которые есть в списке цен + .filter(name__isnull=False) + ) + + def list_matches(key_pk: int, add_products: bool = True) -> QuerySet[Match]: """Получение списка возможных соответствий Ключ - Продукт.""" subquery = Match.objects.filter(key_id=key_pk).select_related("product")