bug fixes

This commit is contained in:
Alexander Karpov 2023-03-26 15:03:45 +03:00
parent 2d28b3bc48
commit 26b6096009
4 changed files with 34 additions and 6 deletions

View File

@ -20,13 +20,18 @@ class ItemSerializer(serializers.ModelSerializer):
amount = obj.sales.first().amount
if amount == nan:
return 0
return float(amount)
try:
return int(amount)
except ValueError:
return 0
def get_volume(self, obj):
print(obj.volume)
if obj.volume == nan:
return 0
return obj.volume
try:
return int(obj.volume)
except ValueError:
return 0
class Meta:
model = Item

View File

@ -17,7 +17,7 @@ from marking_hack.market.models import Store, Region, StoreItem, Item
class ListStore(generics.ListAPIView):
serializer_class = StoreSerializer
pagination_class = BigResultsSetPagination
queryset = Store.objects.order_by("-id_sp")
queryset = Store.objects.filter(sales__isnull=False).order_by("-id_sp").distinct()
class ListStoreItems(generics.ListAPIView):
@ -74,5 +74,6 @@ class PredictItemsView(generics.GenericAPIView):
else:
print(qs)
items.append({"id": x_item, "predicted_volume": 0})
shop["items"] = items
data["shops"] = shops
return Response(data=data)

View File

@ -0,0 +1,22 @@
# Generated by Django 4.1.7 on 2023-03-26 11:53
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
("market", "0010_itemtransaction_sender_region_code"),
]
operations = [
migrations.AlterModelOptions(
name="storeitem",
options={"ordering": ["date"]},
),
migrations.AlterField(
model_name="city",
name="name",
field=models.CharField(max_length=150),
),
]

View File

@ -15,7 +15,7 @@ class City(models.Model):
fias = models.UUIDField(
default=uuid.uuid4, editable=False, unique=True, db_index=True
)
name = models.CharField(max_length=250)
name = models.CharField(max_length=150)
class Store(models.Model):
@ -110,4 +110,4 @@ class StoreItem(models.Model):
amount = models.IntegerField()
class Meta:
ordering = ["-date"]
ordering = ["date"]