Common form

Form Focus: 
- The field
used to hold regular expression
ChoiceField *****
MultipleChoiceField
CharField
IntegerField
DecimalField
DateField
DateTimeField
EmailField
GenericIPAddressField
FileField

RegexField
- HTML plug-in
is used to generate HTML tags

- special single or multiple select when, whether the data source in real time update? ? ? ? ? *****
from app01 Import Models
class LoveForm (forms.Form):
. Price = fields.IntegerField ()
user_id = fields.IntegerField (
# = widgets.Select the widget (choices = [(0, 'Alex'), (. 1 'Liuhao Chen'), (2 'Yang')])
widget=widgets.Select()
)

def __init__(self,*args,**kwargs):
super(LoveForm,self).__init__(*args,**kwargs)
self.fields['user_id'].widget.choices = models.UserInfo.objects.values_list('id','username')

from django.forms.models import ModelChoiceField
from django.forms.models import ModelChoiceField
class LoveForm(forms.Form):
price = fields.IntegerField()

user_id2 = ModelChoiceField(
queryset=models.UserInfo.objects.all(),
to_field_name='id'
)

注意:依赖models中的str方法

Guess you like

Origin www.cnblogs.com/wenghao/p/11344636.html