一般的な形式

フォームのフォーカス:
-フィールド
の正規表現を保持するために使用
***** ChoiceField
なMultipleChoiceField
CharFieldです
IntegerFieldと
DecimalFieldは
DateFieldの
DateTimeField型
EmailField
GenericIPAddressField
FileFieldに

RegexFieldを
- HTMLプラグインは
、HTMLタグを生成するために使用されて

-特別な単一または複数選択し、リアルタイムでのデータソースかどうか更新?*****
app01インポートモデルから
クラスLoveForm(forms.Form)
価格= fields.IntegerField()
USER_ID = fields.IntegerField(
#= widgets.Selectウィジェット(選択肢= [(0、 'アレックス')、(1。 'Liuhaoチェン')、(2 'ヤン')])
ウィジェット= widgets.Select()


デフ__init __(自己、* argsを、** kwargsから):
スーパー(LoveForm、自己).__のinit __(* argsを、** kwargsから)
self.fields [ 'user_idの'] = widget.choices。 models.UserInfo.objects.values_list( 'ID'、 'ユーザ名')

django.forms.modelsからはModelChoiceFieldをインポート
django.forms.modelsインポートからModelChoiceField
クラスLoveForm(forms.Form):
価格= fields.IntegerField()

user_id2 = ModelChoiceField (
クエリセット= models.UserInfo.objects.all()、
to_field_name = 'ID'


注意:依赖モデル中的STR方法

おすすめ

転載: www.cnblogs.com/wenghao/p/11344636.html