我创建了一个表格:
class KeyForm(ModelForm):
class Meta:
model = Key
fields = ['name', 'access_level', 'permission']
这是呈现表单的视图:
def key(request):
template = 'keys.html'
user = request.user
key = get_object_or_404(Key, user=user)
if key.access_level == "0":
owners = Key.objects.filter(access_level = "0")
ownersFormSet = formset_factory(KeyForm)
context = {
'owners': owners,
'ownersFormSet': ownersFormSet,
}
return render(request, template, context)
我想将“所有者”查询集中的数据绑定到“所有者表单集”。我正在迭代模板中的“所有者”,所以我可以在模板的每次迭代中绑定表单数据吗?