Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django template IF condition with logical breckets and precedence order

In my django template I have

{% if object_not_readonly and user_is_worker or user_is_admin %}

Django doc tell me

Use of both and and or clauses within the same tag is allowed, with and having higher precedence than or

I think this is not obvious way to declare logical precedence in IF clause.

Question is:

Is it something like {% if object_not_readonly and ( user_is_worker or user_is_admin ) %} condition in django template language, with obvious clause like if A and (C or B) and (not Z)?

like image 405
Y.N Avatar asked Oct 29 '22 23:10

Y.N


1 Answers

It's not clear what you're asking here, or what result you are trying to achieve with your example statement:

{% if object_not_readonly and user_is_worker or user_is_admin %}

To clarify what they mean in the reference docs by "Use of both and and or clauses within the same tag is allowed, with and having higher precedence than or", the above statement would be evaluated as:

{% if (object_not_readonly and user_is_worker) or user_is_admin %}

which is not the same as {% if object_not_readonly and ( user_is_worker or user_is_admin ) %}

like image 147
Joe S Avatar answered Nov 15 '22 02:11

Joe S