python - 在学校管理系统中添加登录/注销功能
问题描述
我想在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)
解决方案
我猜你是 Django 新手,没问题,我也在开发一个学校管理系统:
https://gitlab.com/charanjit-singh/schoolmanagement
它在 Django 中,我已经实现了你所要求的功能,转到链接,克隆存储库并检查视图和模型,如果有任何关于 gitlab 的问题,请告诉我。
推荐阅读
- ios - 如何在 iOS 中为特定的相机视图控制器强制横向方向
- r - 在 R 中加入/匹配数据帧
- git - 无法使用 git 命令将文件推送到 GitHub
- ios - 错误:无法解析构建文件:XCBCore.BuildFile
- java - 在不同线程中具有读取器和写入器的 Java 复制文件(使用 BlockingQueue)
- excel - Excel中的分组和求和
- c++ - C++ 套接字错误 C1083:无法打开包含文件:'unistd.h':没有这样的文件或目录
- windows - TFS Git 存储库在 Windows 命令提示符上不断询问凭据
- python - 访问字典时字符串索引必须是整数(错误)
- javascript - 在Vue中路由后未定义的auth0变量