mirror of
https://github.com/marking-hack/backend.git
synced 2024-11-24 10:23:43 +03:00
fixed data views
This commit is contained in:
parent
26b6096009
commit
61004cb5db
|
@ -27,11 +27,11 @@ class ItemSerializer(serializers.ModelSerializer):
|
|||
|
||||
def get_volume(self, obj):
|
||||
if obj.volume == nan:
|
||||
return 0
|
||||
return 1
|
||||
try:
|
||||
return int(obj.volume)
|
||||
except ValueError:
|
||||
return 0
|
||||
return 1
|
||||
|
||||
class Meta:
|
||||
model = Item
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
from django.db.models import Count
|
||||
from rest_framework import generics
|
||||
from rest_framework.generics import get_object_or_404
|
||||
from rest_framework.response import Response
|
||||
|
@ -17,7 +18,13 @@ from marking_hack.market.models import Store, Region, StoreItem, Item
|
|||
class ListStore(generics.ListAPIView):
|
||||
serializer_class = StoreSerializer
|
||||
pagination_class = BigResultsSetPagination
|
||||
queryset = Store.objects.filter(sales__isnull=False).order_by("-id_sp").distinct()
|
||||
queryset = (
|
||||
Store.objects.filter(sales__isnull=False)
|
||||
.order_by("-id_sp")
|
||||
.distinct()
|
||||
.annotate(num_sales=Count("sales"))
|
||||
.order_by("-num_sales")
|
||||
)
|
||||
|
||||
|
||||
class ListStoreItems(generics.ListAPIView):
|
||||
|
@ -27,11 +34,12 @@ class ListStoreItems(generics.ListAPIView):
|
|||
def get_queryset(self):
|
||||
store = get_object_or_404(Store, id_sp=self.kwargs["id_sp"])
|
||||
ids = (
|
||||
StoreItem.objects.filter(store=store)
|
||||
StoreItem.objects.filter(store=store, amount__gte=10)
|
||||
.values_list("item", flat=True)
|
||||
.distinct()
|
||||
)
|
||||
return Item.objects.filter(id__in=ids)
|
||||
|
||||
return sorted(Item.objects.filter(id__in=ids), key=lambda x: x.sales.last().amount, reverse=True)
|
||||
|
||||
|
||||
class RegionListView(generics.ListAPIView):
|
||||
|
|
Loading…
Reference in New Issue
Block a user