python - Tag If in template django -


working code:

  {% if request.user.manager.position != 'e' %}       {% endif %} 

models.py

position_choices = (('m', u'manager'), ('e', u'staff'), ('u', u'other_staff')) class manager(models.model): ...     position = models.charfield(max_length=1, choices=position_choices, default='m') 

models.py proj

class project(models.model):     manager = models.foreignkey(manager, blank=true, null=true, related_name='manager_set')     other_staff = models.foreignkey(manager, blank=true, null=true, related_name='staff_set')     staff= models.foreignkey(manager, blank=true, null=true, related_name='otherstaff_set') 

i'm displaying blocks on page html, depending on staff position. in past there 1 staff, 2. try:

 {% if request.user.manager.position in ['e', 'u'] %} 

result:

could not parse remainder: '['e',' '['e',' 

could correct query, please.

django templates doesn't support list literals, easiest way pass list ['e', 'u'] variable , later do:

{% if request.user.manager.position in allowed_positions %} 

Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -