我创建了一个表单:
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)
我想将'owner'查询集中的数据绑定到'ownersFormSet'。我在模板中迭代'所有者',所以我可以在模板的每次迭代中绑定表单数据吗?
答案 0 :(得分:0)