Example #1
0
class DateTimeModel(models.Model):
    # 可以设置 快捷操作
    # options1 可以是个dict 也可以是个str,
    # 但是最终 是要一个完整的json串,
    # 否则可能导致报错控件无法显示出来
    # 文档地址:https://element.eleme.cn/2.13/#/zh-CN/component/datetime-picker
    options1 = """
    {
          shortcuts: [{
            text: '今天',
            onClick(picker) {
              picker.$emit('pick', new Date());
            }
          }, {
            text: '昨天',
            onClick(picker) {
              const date = new Date();
              date.setTime(date.getTime() - 3600 * 1000 * 24);
              picker.$emit('pick', date);
            }
          }, {
            text: '一周前',
            onClick(picker) {
              const date = new Date();
              date.setTime(date.getTime() - 3600 * 1000 * 24 * 7);
              picker.$emit('pick', date);
            }
          }]
        }
    """
    f1 = fields.DateTimeField(verbose_name='DateTime日期时间1', options=options1)

    f2 = fields.DateTimeField(verbose_name='DateTime日期时间2',
                              default=timezone.now,
                              clearable=False,
                              help_text='不可清除')

    f3 = fields.DateTimeField(verbose_name='DateTime日期时间3',
                              default=timezone.now,
                              align='right',
                              clearable=False,
                              editable=False,
                              readonly=True,
                              help_text='不可编辑')

    class Meta:
        verbose_name = 'DateTime日期时间'
        verbose_name_plural = 'DateTime日期时间'
Example #2
0
class Department(models.Model):
    name = fields.CharField(max_length=128,
                            verbose_name='部门名',
                            help_text='一个部门的名字应该唯一',
                            unique=True,
                            db_index=True)
    create_time = fields.DateTimeField(verbose_name='创建时间', auto_now=True)

    class Meta:
        verbose_name = "部门"
        verbose_name_plural = "部门管理"

    """
        如果有__unicode__ 方法,将会优先调用,没有在调用__str__方法
    """

    def __unicode__(self):
        return '部门' + self.name

    def __str__(self):
        return self.name
Example #3
0
class Employe(models.Model):
    name = fields.CharField(max_length=128,
                            verbose_name='名称',
                            help_text='员工的名字',
                            null=False,
                            blank=False,
                            db_index=True)

    avatar_img = fields.ImageField(verbose_name='照片',
                                   null=True,
                                   blank=False,
                                   help_text='员工的照片,在列表会默认显示为图片')

    gender_choices = (
        (0, '未知'),
        (1, '男'),
        (2, '女'),
    )
    # images = fields.ManyToManyField(Image,  blank=True, verbose_name='照片列表')

    gender = fields.IntegerField(choices=gender_choices,
                                 verbose_name='性别',
                                 default=0)

    idCard = fields.CharField(max_length=18,
                              verbose_name='身份证号',
                              help_text='18位的身份证号码',
                              blank=True,
                              null=True)
    phone = fields.CharField(max_length=11, verbose_name='手机号')

    birthday = fields.DateField(verbose_name='生日')
    time = fields.TimeField(verbose_name='时间', auto_now=True)

    department = fields.ForeignKey(Department,
                                   on_delete=models.SET_NULL,
                                   blank=False,
                                   null=True,
                                   verbose_name='部门',
                                   db_index=True)

    title = fields.ForeignKey(Title,
                              on_delete=models.SET_NULL,
                              blank=False,
                              null=True,
                              verbose_name='职务',
                              db_index=True)

    enable = fields.SwitchField(verbose_name='状态', default=True)
    create_time = fields.DateTimeField(verbose_name='创建时间', auto_now=True)

    update_time = fields.DateTimeField(verbose_name='更新时间', auto_now=True)

    def test1(self):
        return format_html('<img src="{}" height="50" width="50">',
                           'https://www.88cto.com/static/images/logo.png')

    def test2(self):
        if self.title:
            return format_html('<span style="color:red;">{}</span>',
                               self.title.name)
        else:
            if self.department:
                return format_html('<span style="color:red;">{}</span>',
                                   self.department.name)

    def department_id(self):
        if self.department:
            return self.department.id

        return ""

    department_id.short_description = '部门id'
    test2.short_description = '测试'

    class Meta:
        verbose_name = "员工"
        verbose_name_plural = "员工管理"
        permissions = (('test', 'test111'), ('test2', 'test222'), ('Simpleui',
                                                                   'simpleui'))

    def __str__(self):
        return self.name