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

  • 相关阅读:
    6种基本排序(C++实现)
    关于 ^ 异或 及 无中间变量进行交换
    清理C盘旧驱动
    sqlmap基本使用
    http头部注入
    waf绕过注入
    mysql报错注入
    Burp Suite工具使用
    mysql注入
    Linux网络配置
  • 原文地址:https://www.cnblogs.com/wumingxiaoyao/p/6530917.html
Copyright © 2011-2022 走看看