57
and
has higher precedence than or
, so you can just write the decomposed version:
{% if user.username in req.accepted.all and user.username not in req.declined.all or
user.username not in req.accepted.all and user.username in req.declined.all %}
For efficiency, using with
to skip reevaluating the querysets:
{% with accepted=req.accepted.all declined=req.declined.all username=user.username %}
{% if username in accepted and username not in declined or
username not in accepted and username in declined %}
...
{% endif %}
{% endwith %}
17
Rephrased answer from the accepted one:
To get:
{% if A xor B %}
Do:
{% if A and not B or B and not A %}
It works!
- [Django]-How do you change the collation type for a MySQL column?
- [Django]-How can I change the way a boolean prints in a django template?
- [Django]-How to mock python's datetime.now() in a class method for unit testing?
Source:stackexchange.com