xadmin2 django 搭建学生系统 model层

import xadmin
from django.db import models

class Class(models.Model):
    class_name = models.CharField(verbose_name='班级',max_length=100)

    class Meta:
        verbose_name = '班级'
        verbose_name_plural='班级'

    def __str__(self):
        return self.class_name


class Grade(models.Model):
    grade_name = models.CharField(verbose_name='年级',max_length=100)

    class Meta:
        verbose_name = '年级'
        verbose_name_plural='年级'

    def __str__(self):
        return self.grade_name




class Students(models.Model):
    class Meta:
        verbose_name = '学生'
        verbose_name_plural = '学生'

    SEX=(
         ('male','男'),
         ('female','女')
    )
    name = models.CharField(verbose_name='学生姓名', max_length=50)
    sex = models.CharField(choices=SEX,verbose_name='性别', max_length=50)
    age = models.IntegerField(verbose_name='年龄')
    address = models.CharField(verbose_name='家庭住址', max_length=250, blank=True)
    enter_date = models.DateField(verbose_name='入学时间')
    remarks = models.TextField(verbose_name='备注', blank=True)
    grade_name = models.ForeignKey(Grade,verbose_name='所在年级',on_delete=models.CASCADE,blank=True,null=True)
    class_name = models.ForeignKey(Class,verbose_name='所在班级',on_delete=models.CASCADE,blank=True,null=True)

    def __str__(self):
        return self.name
# 显示的列
class ClassAdmin(object):
    list_display = ('class_name',)

class GradeAdmin(object):
    list_display = ('grade_name',)
# 注册 显示在侧边栏 不同的管理层需要注册多个
xadmin.site.register(Class,ClassAdmin)
xadmin.site.register(Grade,GradeAdmin)
阅读更多
想对作者说点什么?

博主推荐

换一批

没有更多推荐了,返回首页