我正在創建一個醫生預約系統,我也包含了處方
class Prescription(models.Model):
id = models.UUIDField(default=uuid.uuid4, primary_key=True, editable=False)
user = models.ForeignKey(User, on_delete=models.CASCADE)
doctor = models.ForeignKey(Doctor, null = True, on_delete=models.SET_NULL)
clinic = models.ForeignKey(Clinic, on_delete=models.SET_NULL)
我在想如果醫生出于某種原因洗掉了他的帳戶,如果發生這種情況,醫生或診所可以設定為空嗎?
uj5u.com熱心網友回復:
您可以在 models.py 中添加doctor_name和clinic_name欄位:
class Prescription(models.Model):
id = models.UUIDField(default=uuid.uuid4, primary_key=True, editable=False)
user = models.ForeignKey(User, on_delete=models.CASCADE)
doctor = models.ForeignKey(Doctor, null = True, on_delete=models.SET_NULL)
clinic = models.ForeignKey(Clinic, on_delete=models.SET_NULL)
doctor_name = models.CharField(max_length=100, blank=False)
clinic_name = models.CharField(max_length=100, blank=False)
并且每次都加上醫生的名字和診所的名字。然而,這是非常多余的......
實際上,這里是 stackoverflow 的資料庫架構 -> url。
如您所見,OwnerDisplayName帖子仍然具有作者姓名。
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/334390.html
標籤:Python 姜戈 django-models 数据库设计
上一篇:Django令牌物件更新錯誤:django.db.utils.IntegrityError:唯一約束失敗:authtoken_token.user_id
下一篇:django.core.exceptions.FieldError:無法將關鍵字“productcategory_id”決議為欄位。選項有:國家/地區、country_id、id、名稱、供應商?
