forms.py
from django import forms
from .models import VendorApplication, VendorAppWorkFlow
import MySQLdb as mdb
from django.forms.fields import DateField, ChoiceField, MultipleChoiceField
from django.forms.widgets import RadioSelect, CheckboxSelectMultiple
from django.forms.extras.widgets import SelectDateWidget
con = mdb.connect('', '', '', '');
cursor1 = con.cursor()
cursor1.execute("select * from vendorapp_sharetable;")
columns = cursor1.description
num_fields = len(cursor1.description)
field_names = [i[0] for i in cursor1.description]
class CheckForm(forms.Form):
for index in range(num_fields):
field_names[index] = forms.BooleanField(required=False, label=field_names[index])
我想在forms.py
没有选择的情况下将 field_names 值添加到复选框列表中,或者我如何在选择中迭代它们以拥有checkboxMultiselect widget
. 由于field_names
我的应用程序中的数量不同,因此难以将它们添加到选项中并使用复选框小部件。