I'm sure there is something silly I'm missing here, but I'm trying to use ifequal to evaluate a template variable.
Here's my model:
USER_TYPES = (
('instructor', 'Instructor'),
('student', 'Student'),
)
class UserProfile(models.Model):
type = models.CharField(
choices=USER_TYPES, max_length=12
)
user = models.ForeignKey(
User,
unique=True
)
def __unicode__(self):
return u'%s' % (self.type)
...and I'm using this in the template:
{% ifequal user.userprofile_set.get student %}
You're a student!
{% endifequal %}
When I simply print out {{ user.userprofile_set.get }} I get:
student
Not sure what I'm missing - any help is appreciated!
ifequal is deprecated... but I think that this works:
{% ifequal user.userprofile_set.get.type "student" %}
Your a student!
{% endifequal %}
来源:https://stackoverflow.com/questions/11733651/using-ifequal-in-django