With a simple model:
class Card(models.Model):
name = models.CharField(max_length=25)
rate = models.IntegerField(default=0)
good = models.BooleanField(default=False)
it is possible to generate a form with:
class CardForm(ModelForm):
class Meta:
model = Card
fields = '__all__'
which then includes all the model fields through a simple template with major part as:
<table>
{{ form.as_table }}
</table>
But when showing through a ListView
subclass as:
class CardShow(ListView):
model = Card
template_name = 'myapp/show.html'
it still requires a template where all the model fields are explicitly named as:
<ul>
{% for card in object_list %}
<li>{{ card.name }}, {{ card.rate }}, {{ card.good }}</li>
{% endfor %}
</ul>
Is there any way to auto-generate HTML code for view (show), just like the form has form.as_table
, form.as_p
, and form.as_ul
?