标签:tip app 依赖 get import 复选框 echo queryset widget
#单选方式一 from django.forms import Form from django.forms import fields from django.forms import widgets from app01 import models class TestForm(Form): user = fields.CharField() group = fields.CharField( choice = [] ) def __init__(self,*args,**kwargs): super(TestForm,self).__init__(*args,**kwargs) self.fields[‘group‘].choices=models.UserGroup.objects.values_list(‘id‘,‘title‘) #单选方式二 # 依赖model中的__str__ from django.forms import Form from django.forms import fields from app01 import models from django.forms.models import ModelChoiceField class TestForm(Form): user = fields.CharField() group = ModelChoiceField(queryset=models.UserGroup.objects.all()) #复选框 from django.forms import Form from django.forms import fields from app01 import models from django.forms.models import ModelMultipleChoiceField class TestForm(Form): user = fields.CharField() group = ModelMultipleChoiceField(queryset=models.UserGroup.objects.all())
标签:tip app 依赖 get import 复选框 echo queryset widget
原文地址:http://www.cnblogs.com/oyoui/p/7520238.html