我希望这样,我需要用户名和密码才能访问该帐户,然后将该用户名另存为“用户”表中的主键,并且该用户名也位于“学生和教师”表中,并且我可以访问从这三个表。 我一直在使用外键和其他东西,但没有帮助,谢谢
我尝试使用Users表模型models.ManytoManyField中的外键来创建抽象用户
**
class CustomUser(AbstractUser):
username = models.IntegerField(primary_key=True, unique=True, default=None)
student = models.ForeignKey(StudentUser, on_delete=models.CASCADE, default=0000)
faculty = models.ForeignKey(FacultyUser, on_delete=models.CASCADE, default=0000)
first_name = models.CharField(max_length = 200)
last_name = models.CharField(max_length = 200)
email = models.EmailField()
class FacultyUser(models.Model):
ROLE_CHOICES = (
('STD', 'student'),
('TCH', 'teacher'),
('CDR', 'coordinator'),
('HOD', 'HOD'),
)
f_code = models.IntegerField(unique=True, primary_key=True, default=None)
role = models.CharField(choices=ROLE_CHOICES, max_length=3)
class StudentUser(models.Model):
DEPARTMENT_CHOICES = (
('CSE', 'Computer Science Engineering'),
('EC', 'Electrical Engineering'),
('ME', 'Mechanical Engineering'),
('CE', 'Civil Engineering'),
('EX', 'Electronics Engineering'),
('FT', 'Fire Technology'),
)
SEMESTER_CHOICES = (
('1', 'First'),
('2', 'Second'),
('3', 'Third'),
('4', 'Fourth'),
('5', 'Fifth'),
('6', 'Sixth'),
('7', 'Seventh'),
('8', 'Eighth'),
)
GENDER_CHOICES = (
('M', 'Male'),
('F', 'Female'),
)
SECTION_CHOICES = (
('1', '1'),
('2', '2'),
('3', '3'),
)
department = models.CharField(choices=DEPARTMENT_CHOICES, max_length=3)
dep_section = models.IntegerField(choices=SEMESTER_CHOICES)
sem = models.IntegerField(choices=SEMESTER_CHOICES)
gender = models.CharField(max_length=1, choices=GENDER_CHOICES)
s_code = models.IntegerField(unique=True, primary_key=True, default=None)
**