Having generic fields based on model objects in forms.py in django
We have a model called Permission and we have listed it in a form in django template like this:
{% for item in permissions %}
<tr>
<td class="text-nowrap">{{ item.app }}</td>
<td>
<div class="d-flex">
<div class="form-check me-3 me-lg-5 mb-0 mt-0">
<input class="form-check-input" type="checkbox" name="{{ item.app }}_add" id="{{ item.app }}ManagementWrite">
<label class="form-check-label" for="{{ item.app }}ManagementWrite">add</label>
</div>
<div class="form-check me-3 me-lg-5 mb-0 mt-0">
<input class="form-check-input" type="checkbox" name="{{ item.app }}_read" id="{{ item.app }}ManagementRead">
<label class="form-check-label" for="{{ item.app }}ManagementRead">read</label>
</div>
<div class="form-check me-3 me-lg-5 mb-0 mt-0">
<input class="form-check-input" type="checkbox" name="{{ item.app }}_update" id="{{ item.app }}ManagementUpdate">
<label class="form-check-label" for="{{ item.app }}ManagementUpdate">update</label>
</div>
<div class="form-check mb-0 mt-0">
<input class="form-check-input" type="checkbox" name="{{ item.app }}_delete" id="{{ item.app }}ManagementDelete">
<label class="form-check-label" for="{{ item.app }}ManagementDelete">delete</label>
</div>
</div>
</td>
</tr>
{% endfor %}
So here We have four options for read , write , update and delete for each object in the Permission table .
But How can i make a form in forms.py for this that i have BoleanFields for each access level? for example four field for ticket app (read , write , update , delete) and four field for users app as the same .