zoukankan      html  css  js  c++  java
  • django admin 或xdmin list_display search_fields list_filter 如果显示搜索外键或多对多字段

    model

    class UserProfile(AbstractUser):
    
        nick_name = models.CharField(max_length=50, verbose_name=u"昵称", default="")
        gender = models.CharField(max_length=6, choices=(("male",u""),("female","")), default="female")
        address = models.CharField(max_length=100, default=u"")
        mobile = models.CharField(max_length=11, null=True, blank=True)
        add_time = models.DateTimeField(auto_now=True)
    
    
        class Meta:
            verbose_name = "用户信息"
            verbose_name_plural = verbose_name
    class Project(models.Model):
        project_name = models.CharField(max_length=200, verbose_name="项目名称", default="")
        project_number = models.CharField(max_length=200,verbose_name="项目编号", default="")
        project_user = models.ForeignKey(UserProfile,verbose_name='项目负责人')
        add_time = models.DateTimeField(auto_now=True)
    
        class Meta:
            verbose_name = "项目信息"
            verbose_name_plural = verbose_name
    
    
    class Center(models.Model):
        center_name = models.CharField(max_length=200, verbose_name="中心名称", default="")
        center_number = models.CharField(max_length=200,verbose_name="中心编号", default="")
        center_user = models.ManyToManyField(UserProfile, verbose_name='中心负责人')
        add_time = models.DateTimeField(auto_now=True)
    
        class Meta:
            verbose_name = "中心信息"
            verbose_name_plural = verbose_name

    admin或xadmin的展示

    class CenterAdmin(object):
        """
        中心列表
        """
    
        list_display = ['id','center_name','center_number','center_user']  #后台自定义显示列
    
        search_fields = ['id','center_name','center_number','center_user__username'] #定义后台搜索 外键或多对多加__双下划线对应的字段名
    
        list_filter = ['id','center_name','center_number','center_user__username'] #通过时间搜索外键或多对多加__双下划线对应的字段名
    
    
    class PatientAdmin(object):
        """
        患者列表
        """
    
        list_display = ['id','patient_number','patient_user']  #后台自定义显示列
    
        search_fields = ['id','patient_number','patient_user__username'] #定义后台搜索 外键或多对多加__双下划线对应的字段名索
    
        list_filter = ['id','patient_number','patient_user__username'] #通过时间搜索外键或多对多加__双下划线对应的字段名
  • 相关阅读:
    设计模式学习笔记之状态模式
    设计模式学习笔记之观察者模式
    设计模式学习笔记之模板方法模式
    设计模式学习笔记之策略模式
    设计模式学习笔记之装饰者模式
    Comparable和Comparator接口的比较
    Java中关键字continue、break和return的区别
    斐波那契数列-兔子问题
    用Java编程计算猴子吃桃问题
    (转载)Java多线程入门理解
  • 原文地址:https://www.cnblogs.com/zhaoyingjie/p/8461162.html
Copyright © 2011-2022 走看看