首页 > 解决方案 > 在学校管理系统中添加登录/注销功能

问题描述

我想在Person模型中添加登录、注销功能,以便任何其他类继承它,例如guardians students staffs也可以获得这些功能。如何做到这一点,有没有更好的方法?

from django.db import models


# simplified



class Person(models.Model):
    Name = models.CharField(max_length=200)
    BirthDate = models.DateField('Date of birth')
    Email = models.EmailField(max_length=200)
    CellPhone = models.CharField(max_length=14)


class Guardian(Person):
    pass


class Student(Person):
    guardians = models.ManyToManyField(Guardian, db_table='Student_Guardian_Bridge')
    Address = models.ForeignKey(Location, on_delete=models.CASCADE)


class Staff_Type(models.Model):
    type_of_staff = models.CharField(max_length=50)

    def __str__(self):
        return self.type_of_staff


class Staff(Person):
    staff_type = models.ForeignKey(Staff_Type, on_delete=models.PROTECT)
    Salary = models.IntegerField()
    guardians = models.ManyToManyField(Guardian, db_table='Staff_Guardian_Bridge')
    Address = models.ForeignKey(Location, on_delete=models.CASCADE)

标签: pythondjangodjango-models

解决方案


我猜你是 Django 新手,没问题,我也在开发一个学校管理系统:

https://gitlab.com/charanjit-singh/schoolmanagement

它在 Django 中,我已经实现了你所要求的功能,转到链接,克隆存储库并检查视图和模型,如果有任何关于 gitlab 的问题,请告诉我。


推荐阅读