Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using ifequal in Django

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!

like image 487
Jeffrey Stilwell Avatar asked Mar 26 '26 23:03

Jeffrey Stilwell


1 Answers

ifequal is deprecated... but I think that this works:

{% ifequal user.userprofile_set.get.type "student" %}
    You're a student! 
{% endifequal %}
like image 171
Goin Avatar answered Mar 29 '26 22:03

Goin



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!