Django enrich QuerySet

I have an Django Application that runs only locally on my machine.

I have two diffrent tabels, with the transaction and the price. Now I want to enrich my transaction with the price.

I wrote something similar already to calculate the average price:

for transaction in transactions:
    filter_date = transaction.timestamp.date()
    price = Price.objects.filter(fiat=cur_id, date=filter_date).first()
    if not price:
        price = PriceTextBackup.objects.filter(fiat=cur_id, date=filter_date.strftime("%d-%m-%Y")).first()
    if price:
        if transaction.amount > 0:
            sats_price=price.price*transaction.amount
            price_list.append(sats_price)
            transaction_counter += transaction.amount

I display the price in a popup on mouseover, the html page looks like this

            {% if transaction.amount >= 0 %}
                <td onmouseover="showPopup({{forloop.counter}}0000)" onmouseout="hidePopup()" class="text-success">{{transaction.fiat_CHF|floatformat:2 |intcomma }}</td>
            {% else %}
                <td class="text-danger">{{transaction.fiat_CHF|floatformat:2 |intcomma }}</td>
            {% endif %}

How can I do the same logic for the price in the queryset?

Вернуться на верх