I'm using generic types in my Profile
model:
user_type = models.ForeignKey(ContentType)
object_id = models.PositiveIntegerField()
details = generic.GenericForeignKey('user_type', 'object_id')
But now I want to check if a user is a certain type from within my template. I can get the user type with {{ user.get_profile.user_type }}
but then what? Or how would I add a method to the model like is_type_xxx
so that I could use it in the template?
I've added the following methods to my Profile
model:
def is_user_type(self, type):
return self.user_type == ContentType.objects.get_for_model(type),
@property
def is_shipper(self):
return self.is_user_type(Shipper),
... *face palm*
The trailing comma was causing it to return a tuple, which evaluates to true.