I have a user model with a profile UserProfile.
Somehow my user can have several type of books: TA, TB, TC, TD.
Those choices are defined in a choices tuple in my model (standard way).
From my template I would like to be able to call
{{ user.get_profile.has_book_type_TA }}
and returns True/False.
TA is the dynamic part, it could be rewritten as:
has_book_type_[type_name]
How can I write this kind of method in my model ?
def has_book_type_(self, type_name):
...
But how to make it callable as get_profile.has_book_type_TA
In the
__init__method for your model, walk through the different types of books and create properties:Then in your templates, checking
user.get_profile.has_book_type_TAshould work.