Say I have a model like:
from django.db import models
USER_TYPE_CHOICES = (
(1, 'Free'),
(2, 'Paid'),
)
class Account(models.Model):
name = models.CharField(max_length=20)
user_type = models.IntegerField(default=1, choices=TYPE_CHOICES)
and in a template I want to test the user_type to show a special section if the user is of type 'Paid'.
I'd like to do something similar to a C #define or constant to test user_type. So my template code would look like:
{% ifequal user_type PAID_ACCOUNT %}
instead of using a magic number like:
{% ifequal user_type 2 %}
What is the most elegant way to do this in Django? Should I just define a custom context processor with FREE_ACCOUNT and PAID_ACCOUNT in it? Perhaps a template tag?
Thank you!