Django query with TruncHour for multiple product with each group latest sum. How to do that?

Viewed 31

The scenario is: The product database price update every hour. People can add product to wishlist. Wishlist page has some graph. That shows last 24 hours price changes. I want to show every hour price change of all his wishlist product for last 24 hours.

I am trying but I can't complete the query. What I am trying is given below:

now = datetime.datetime.now()
last_day = now - datetime.timedelta(hours=23)
x = (
        FloorPrice.objects.filter(
            product__in=vault_products_ids, creation_time__gte=last_day
        )
        .annotate(hour=TruncHour("creation_time"))
        .values("hour", "floor_price")
    )

Suppose I add in wishlist 4 product.

Now I want each hour 4 products sum with that hour latest entry(each hour each product has multiple floor price, so we need to pick the last entry of each product on that hour).

0 Answers
Related