美好的一天,我得到了以下模型,但我相信有更好的方法來實現我所做的。我的擔心是關於擴展GeneralUser,我並不真的覺得它是一個好主意。 以我現在正在做的方式擴展GeneralUser是否好,還是最好在我想引用它的所有模型中爲GeneralUser創建一個外鍵?如何在django中正確使用多個用戶模型?
class GeneralUser(models.Model):
user = models.ForeignKey(User, unique=True)
profile_picture = models.ImageField()
gender = models.CharField(max_length=1, choices=choices)
country = models.CharField(max_length=50)
province = models.CharField(max_length=50)
city = models.CharField(max_length=50)
street = models.CharField(max_length=50)
contact_number = models.CharField(max_length=50)
post_code = models.IntegerField(max_length=5)
date_of_birth = models.DateField()
class Administrator(GeneralUser):
admin_id = models.CharField(max_length=50)
class Patient(GeneralUser):
patient_id = models.CharField(max_length=10)
class Doctor(GeneralUser):
doctor_id = models.CharField(max_length=10)
class Department(models.Model):
doctor_id = models.ForeignKey(Doctor, related_name='doctor')
class Bill(models.Model):
patient_id = models.ForeignKey(Patient, related_name='patient')
class Appointment(models.Model):
patient_id = models.ForeignKey(Patient, related_name='patient')
doctor_id = models.ForeignKey(Doctor, related_name='doctor')
class PatientRecord(models.Model):
pass
class Contact(models.Model):
full_name = models.CharField(max_length=80)
email = models.EmailField(help_text='[email protected]')
contact_number = models.CharField(max_length=14, help_text='+27 074 859 81 93')
message = models.TextField(help_text='Please, type in your message')
任何幫助或想法如何更好地設計表和關係?
爲什麼你不用組來處理? – mtt2p
@ mtt2p不知道如何與羣組 – mkwilfreid
做什麼你的目標是什麼? – mtt2p