Skip to content

Commit

Permalink
Merge pull request #33 from hackathone-prosept-team2/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
ratarov authored Dec 7, 2023
2 parents 94432d7 + 3f2bac2 commit aa19153
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 3 deletions.
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ http://81.31.246.5/ <br>
email: [email protected]
password: Password-123
```
## Архивы и фото
## Архивы и фото приложения
Вставить сюда фотки с сайта

## FRONTEND:
Expand All @@ -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
Expand Down
2 changes: 2 additions & 0 deletions apps/api/v1/dealers/serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,15 @@ 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
fields = BaseKeySerializer.Meta.fields + (
"name",
"last_price",
"status",
"url",
)

def get_status(self, obj):
Expand Down
4 changes: 2 additions & 2 deletions apps/dealers/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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
22 changes: 22 additions & 0 deletions apps/dealers/crud.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
),
Expand All @@ -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")
Expand Down

0 comments on commit aa19153

Please sign in to comment.