zoukankan      html  css  js  c++  java
  • Pyhton学习——Day59

    参考博客:
    http://www.cnblogs.com/wupeiqi/articles/6144178.html

    Form
    1. 验证
    2. 生成HTML(保留上次输入内容)
    3. 初始化默认是

    Form重点:
    - 字段
    用于保存正则表达式
    ChoiceField *****
    MultipleChoiceField
    CharField
    IntegerField
    DecimalField
    DateField
    DateTimeField
    EmailField
    GenericIPAddressField
    FileField

    RegexField
    - HTML插件
    用于生成HTML标签

    - 特殊的单选或多选时,数据源是否能实时更新?????*****
    from app01 import models
    class LoveForm(forms.Form):
    price = fields.IntegerField()
    user_id = fields.IntegerField(
    # widget=widgets.Select(choices=[(0,'alex'),(1,'刘皓宸'),(2,'杨建'),])
    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方法






    Win a contest, win a challenge
  • 相关阅读:
    31款简单实用的CSS+JS下拉菜单脚本
    POWERDESIGNER 15 反向生成PDM[转]
    WCF异常信息
    下载文件
    分区表的维护 ORA14402 更新分区关键字列
    [转]Winform框架之字典数据管理
    用例图(User Case)
    datetime的时值
    JS date对象的减法处理
    JS获取当前页面的高度
  • 原文地址:https://www.cnblogs.com/pandaboy1123/p/8915531.html
Copyright © 2011-2022 走看看