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中实现

  • 相关阅读:
    POJ-1182 食物链
    hdu 1879 继续畅通工程
    HDU 2604 Queuing
    hdu 1232 畅通工程
    POJ-1611 The Suspects
    Free DIY Tour
    Tr A
    不容易系列之(3)―― LELE的RPG难题
    W3C标准冒泡、捕获机制
    JavaScript 浏览器事件解读
  • 原文地址:https://www.cnblogs.com/wumingxiaoyao/p/6530917.html
Copyright © 2011-2022 走看看