@register.filter
def quantity_ordered(product, order):
    try:
        return order.items.values('quantity').get(product=product)['quantity']
    except ObjectDoesNotExist:
        return 0
e.g. {% if product|quantity_ordered:plata.order > 0 %} ... {% endif %}
dataset/ETHPy150Open matthiask/plata/plata/shop/templatetags/plata_tags.py/quantity_ordered