I want to show a table containing a set of model objects.
My model class:
from django.dbfrom django.db import models
from django.utils.translation import ugettext_lazy as _
class DamageKind(models.Model):
name = models.CharField(_('damage kind'), max_length=64)
regions = models.ManyToManyField(Region)
def __str__(self):
return self.name
class Meta:
verbose_name = _('damage kind')
verbose_name_plural = _('damage kinds')
my form class:
from django import forms
from crispy_forms.helper import FormHelper
from .models import DamageKind
class DamageKindList(forms.Form):
def __init__(self, *args, **kwargs):
self.damagekinds = kwargs.pop('damagekinds', [])
self.helper = FormHelper()
self.helper.form_method = 'post'
super().__init__(*args, **kwargs)
My base template base.html:
<!DOCTYPE html>
<html>
<body>
{% block list %}
{% endblock %}
</body>
</html>
my list_damagekinds.html:
{% extends "./base.html" %}
{% load crispy_forms_tags %}
{% block list %}
<form action="" method="post">
{% csrf_token %}
{{ damagekind_form }}
</form>
{% endblock %}
and my views.py:
def list_damagekinds(request):
damagekinds = DamageKind.objects.all()
return render(
request,
'damage/list_damagekinds.html',
{'damagekind_form': DamageKindList(damagekinds=damagekinds), }
)
so my question is how I can make a table containing all the names of the damagekinds by not beeing editable, so just showing these. And with using the crispy_forms FormHelper and not code it into the template.
Thanks in advance.