我有一个这样的带有输入字段的表格。我如何在Django中获得这些值。我将values="[1][{{ functionality.id }}]"
用于多个循环。
template.html
<form action="" method="POST">
<tr>
{% for functionality in functionalities %}
<td>{% ifchanged %}{{ functionality.acl_controller}}{% endifchanged %}</td>
<td>
{{ functionality.acl_functionality }}
</td>
<td>
<div class="form-check form-check-flat text-dark">
<label class="form-check-label">
<input type="checkbox" class="form-check-input" values="[1][{{ functionality.id }}]"> .
<i class="input-helper"></i></label>
</div>
</td>
<td>
<div class="form-check form-check-flat text-dark">
<label class="form-check-label">
<input type="checkbox" class="form-check-input" values="[2][{{ functionality.id }}]"> .
<i class="input-helper"></i></label>
</div>
</td>
</tr>
{% endfor %}
</form>
Views.py
@login_required
def AclView(request):
form = ACLForm()
functionalities = AclFunctionality.objects.all().order_by('acl_controller')
companies = Company.objects.exclude(company_is_deleted=True)
query = request.GET.get('query')
company = 0
if query:
# list_query = companies
company = Company.objects.get(id=query)
print(company)
return render(request, 'acl/acl-dashboard.html', { 'functionalities': functionalities,
'companies': companies,
'company': company,
'form': form
})
我想在AclRoleAccess模型(数据库)中保存多个数据
Models.py
class AclRoleAccess(models.Model):
acl_role = models.ForeignKey(ACLRoles, on_delete=models.CASCADE)
acl_company = models.ForeignKey(Company, on_delete=models.CASCADE)
acl_functionality = models.ForeignKey(AclFunctionality, on_delete=models.CASCADE)
acl_has_access = models.BooleanField()
class Meta:
db_table = "acl_role_accesses"
我如何同时在AclRoleAccess
和acl_company=1
(第一个数组值)中将二维数组保存在acl_roles=1 or 2
多个数据中