Hello All,
I started to code in Django quite recently, so maybe my question is a bit wierd. Recently I needed to render the CharField fields from the model into simple static text in html , but I figured out that it seems it's not that simple in this case as I could think, or I am doing something wrong...
I have this model:
class Tag(models.Model):
CATEGORIES = (
(0, 'category0'),
(1, 'category1'),
(2, 'category2'),
(3, 'category3'),
(4, 'category4'),
(5, 'category5'))
name = models.CharField(max_length=20)
description = models.CharField(max_length=100, blank=True)
category = models.IntegerField(default=0)
user = models.ForeignKey(User)
Form class for it is:
class TagForm(ModelForm):
category = ChoiceField(choices=Tag.CATEGORIES)
class Meta:
model = Tag
in views I create the formset with multiple Tag objects in a single form with providing TagForm class for each Tag object in it:
TagsFormSet = modelformset_factory(Tag,exclude=('user'),form=TagForm,extra=0)
form = TagsFormSet(queryset=all_tags)
and in the template I have:
{{ form.management_form }}
{% for tagform in form.forms %}
{{ tagform }}
<hr>
{% endfor %}
But this way in the html, "name" and "description" fields of the model are always rendered as input text field. I would like to have them in the html just as normal static text without anything (in that html at the moment I only need to display them). Is there any quick solutions for this case?
thanks in advance for the help