zoukankan      html  css  js  c++  java
  • from 动态显示select数据

    一、
    ModelChoiceField(ChoiceField)
        ...                        django.forms.models.ModelChoiceField
        queryset,                  # 查询数据库中的数据
        empty_label="---------",   # 默认空显示内容
        to_field_name=None,        # HTML中value的值对应的字段
        limit_choices_to=None      # ModelForm中对queryset二次筛选
     
    ModelChoiceField要配合models使用:
    def __str__(self):
      return self.name
     
    二、

    def __init__(self, *args, **kwargs):
      super(RecordForm, self).__init__(*args, **kwargs)
      self.fields['machine_room'].widget.choices = MachineRoom.objects.all().values_list('machine_room_id','machine_room_name')
      self.fields['man'].widget.choices = UserInfo.objects.all().values_list('user_id', 'user_name')

    以上2中方式都在form中实现

  • 相关阅读:
    JSONP
    函数式编程
    Cookie
    IE userData
    Web Storage
    前端学PHP之会话Session
    数据结构之归并排序
    数据结构之冒泡排序
    数据结构之插入排序
    数据结构之选择排序
  • 原文地址:https://www.cnblogs.com/wumingxiaoyao/p/6530917.html
Copyright © 2011-2022 走看看