Added number_of_days_since_restocked property to ItemListing
+ selling command now displays how many days since the last restockdoc_update
parent
bd9dad6c82
commit
f5fc606c0c
|
@ -437,16 +437,14 @@ def get_selling(item_name, sort):
|
|||
for shop_id in shop_ids:
|
||||
shop = Shop.objects.get(pk=shop_id['shop_id']).json
|
||||
|
||||
item_query = ItemListing.objects.annotate(normalized_price=F('price') / F('amount')) \
|
||||
.filter(item_name__icontains=item_name, shop_id=shop_id['shop_id']) \
|
||||
.order_by(sort) \
|
||||
.values("item_name", "price", "amount")
|
||||
item_query = ItemListing.objects.filter(
|
||||
item_name__icontains=item_name, shop_id=shop_id['shop_id']).order_by(sort)
|
||||
|
||||
item_list = []
|
||||
for item in item_query:
|
||||
item_list.append(item)
|
||||
|
||||
shop["items"] = item_list
|
||||
shop["items"] = objects_list_to_json(item_list)
|
||||
items.append(shop)
|
||||
|
||||
return items
|
||||
|
|
|
@ -2,6 +2,7 @@ from django.db import models
|
|||
from django.conf import settings
|
||||
from django.urls import reverse
|
||||
from sys import maxsize
|
||||
import datetime
|
||||
|
||||
from GeoffreyApp.util import create_token, objects_list_to_json
|
||||
|
||||
|
@ -413,6 +414,15 @@ class ItemListing(models.Model):
|
|||
else:
|
||||
return self.price / self.amount
|
||||
|
||||
@property
|
||||
def number_of_days_since_restocked(self):
|
||||
"""
|
||||
days since this item was restocked
|
||||
"""
|
||||
days = (datetime.datetime.now().astimezone() - self.date_restocked.astimezone()).days
|
||||
|
||||
return days
|
||||
|
||||
@property
|
||||
def json(self):
|
||||
"""
|
||||
|
@ -425,6 +435,7 @@ class ItemListing(models.Model):
|
|||
"price": 1,
|
||||
"amount": 1,
|
||||
"date_restocked": 1553264508,
|
||||
"days_since_restock": 10,
|
||||
"normalized_price": 1,
|
||||
"shop": {}
|
||||
}
|
||||
|
@ -434,6 +445,7 @@ class ItemListing(models.Model):
|
|||
"price": self.price,
|
||||
"amount": self.amount,
|
||||
"date_restocked": self.date_restocked.timestamp(),
|
||||
"days_since_restock": self.number_of_days_since_restocked,
|
||||
"normalized_price": self.normalized_price,
|
||||
"shop": self.shop.json,
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue