To do this, you must use a special filter.
Here are two different ways to do this:
1) You can define a negate filter:
# negate_filter.py from django import template register = template.Library() @register.filter def negate(value): return -value
Then, in your template, add the code {% load negate_filter %} to the top of the page, and then replace {{ -qty }} with {{ qty|negate }} .
2) You can also replace the whole thing with one buy_sell filter, if you want:
# buy_sell_filter.py from django import template register = template.Library() @register.filter def buy_sell(value): if value > 0 : return 'sell %s' % value else : return 'buy %s' % -value
Then your template should be
{% if qty %} Please, sell {{ qty|buy_sell }} products.{% endif %}
You can even include the entire line in the filter and just have the complete template {{qty | buy_sell}}.
Both options are reasonable, depending on the rest of your template. For example, if you have many lines that use the purchase for the negative and sell for the positive, do the second.
source share