models.py:
class MyText(models.Model)
value = models.TextField()
appearance = models.Charfield(
max_length=50,
choices=(
('bold', 'Bold'),
('italic', 'Italic'),
)
)
object:
a_lot_of_text = MyText(value='a lot of text', appearance='bold')
I pass this object via context
in views.py
into HTML template. And I want to check (in HTML) what kind of appearance a_lot_of_text
has, and use certan class
for its <div>
element. In other words, I want to get smth like this:
mytemplate.html (pseudocode):
<style>
bold_class {...}
italic_class {...}
</style>
{% if object.appearance == 'bold' %}
{% somehow i will use 'bold_class' %}
{% elif object.appearance == 'italic' %}
{% somehow i will use 'italic_class' %}
{% endif %}
{% for word in object.value %}
<div class="{{class_that_i_have_chosen_in_if-block}}">{{word}}</div>
{% endfor %}
Because there is a lot of word
in a_lot_of_text
I would like to check my class 1 time, before my for-block
and use it there. I think I could make my own assignment Tag - is it correct solution?