Django admin后台使用simpleui美化(以学生管理系统为例)

Posted FIVESIRRRR

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Django admin后台使用simpleui美化(以学生管理系统为例)相关的知识,希望对你有一定的参考价值。

1.导入simpleui

pip install django-simpleui

2.在setting中注册

 INSTALLED_APPS = [
      \'simpleui\',
      \'django.contrib.admin\',
      \'django.contrib.auth\',
      \'django.contrib.contenttypes\',
      \'django.contrib.sessions\',
      \'django.contrib.messages\',
      \'django.contrib.staticfiles\',
      ...
  ]

3.编写models.py

from django.db import models
class student(models.Model):
    stu_num=models.BigIntegerField(primary_key=True,verbose_name="账号")
    stu_pwd=models.CharField(max_length=32,verbose_name="密码")
    stu_name=models.CharField(max_length=32,verbose_name="学生姓名")
    stu_mingzu=models.CharField(max_length=32,verbose_name="名族")
    stu_sex=models.CharField(max_length=32,verbose_name="性别")
    stu_zhuanye=models.CharField(max_length=32,verbose_name="专业")
    stu_jiguan=models.CharField(max_length=32,verbose_name="籍贯")
    stu_birth=models.DateField(verbose_name="生日")
    stu_pic=models.ImageField(upload_to=\'media\',verbose_name="照片")
    class Meta:
        # 末尾不加s
        verbose_name_plural = \'学生表\'
    def __str__(self):
        return self.stu_name


class course(models.Model):
    co_num=models.AutoField(primary_key=True)
    co_name=models.CharField(max_length=32)
    co_teacher=models.CharField(max_length=32)
    class Meta:
        # 末尾不加s
        verbose_name_plural = \'课程表\'
    def __str__(self):
        return self.co_name

class chco(models.Model):
    chco_num = models.AutoField(primary_key=True)
    chco_st = models.ForeignKey(student,on_delete=models.CASCADE)
    chco_co=models.ForeignKey(course,on_delete=models.CASCADE)
    class Meta:
        verbose_name_plural = \'选课表\'

class term(models.Model):
    te_num= models.AutoField(primary_key=True)
    te_name=models.CharField(max_length=32)
    class Meta:
        verbose_name_plural = \'学期表\'
    def __str__(self):
        return self.te_name

class mark(models.Model):
    ma_num=models.AutoField(primary_key=True)
    ma_st=models.ForeignKey(student,on_delete=models.CASCADE)
    ma_xueqi=models.ForeignKey(term,on_delete=models.CASCADE)
    ma_mark=models.IntegerField()
    class Meta:
        verbose_name_plural = \'成绩表\'

class money(models.Model):
    mo_num=models.AutoField(primary_key=True)
    mo_st=models.ForeignKey(student,on_delete=models.CASCADE)
    mo_month=models.IntegerField()
    mo_money=models.IntegerField()
    class Meta:
        verbose_name_plural = \'消费表\'

class book(models.Model):
    bo_num=models.AutoField(primary_key=True)
    bo_name=models.CharField(max_length=32)
    class Meta:
        verbose_name_plural = \'书籍表\'
    def __str__(self):
        return self.bo_name

class lend(models.Model):
    le_num=models.AutoField(primary_key=True)
    le_st=models.ForeignKey(student,on_delete=models.CASCADE)
    le_bo=models.ForeignKey(book,on_delete=models.CASCADE)
    le_start=models.DateTimeField()
    le_end=models.DateTimeField(auto_now=True)
    class Meta:
        verbose_name_plural = \'借书表\'


# Create your models here.

4.在admin.py中添加站点

from django.contrib import admin
from django.contrib import admin
from app.models import student,course,chco,mark,money,book,lend,term
admin.site.site_header="学生管理系统"
admin.site.site_title="学生管理系统"
class Student(admin.ModelAdmin):
    list_display = (\'stu_num\',\'stu_name\')
    search_fields = (\'stu_num\',\'stu_name\')
    list_filter = (\'stu_num\',\'stu_name\')
class Course(admin.ModelAdmin):
    list_display = (\'co_name\',\'co_teacher\')
class Chco(admin.ModelAdmin):
    list_display = (\'chco_st\',\'chco_co\')
class Mark(admin.ModelAdmin):
    list_display = (\'ma_st\',\'ma_xueqi\',\'ma_mark\')
class Money(admin.ModelAdmin):
    list_display = (\'mo_st\',\'mo_month\',\'mo_money\')
class Lend(admin.ModelAdmin):
    list_display = (\'le_st\',\'le_bo\',\'le_start\',\'le_end\')
admin.site.register(student,Student)
admin.site.register(course,Course)
admin.site.register(chco,Chco)
admin.site.register(mark,Mark)
admin.site.register(money,Money)
admin.site.register(book)
admin.site.register(lend,Lend)
admin.site.register(term)

# Register your models here.

5.运行截图

 

 

 

 

 

以上是关于Django admin后台使用simpleui美化(以学生管理系统为例)的主要内容,如果未能解决你的问题,请参考以下文章

Django admin后台使用simpleui美化(以学生管理系统为例)

Django admin后台美化(极其简单)

Django+SimpleUI

django 后台怎么执行thread

django-xadmin后台列表页勾选复选框怎么打开?

邂逅Django——数据库配置