2015-05-14 44 views
0

工作代碼:標記如果在模板Django的

{% 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爲凸出

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') 

我的HTML頁面顯示一些塊,這取決於員工的位置。但在過去,只有一個工作人員,現在卻2.我嘗試:

{% if request.user.manager.position in ['E', 'U'] %} 

結果:

Could not parse the remainder: '['E',' from '['E',' 

你能幫助正確的查詢,請。

回答

3

Django模板不支持列表中的文字,我會說最簡單的方法是通過你的列表['E', 'U']爲變量,後來做:

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

嘗試發送列表與valids位置模板作爲一個變量。您無法直接在模板中定義列表。