我在 Django 1.5 中有这些模型
class Number(models.Model):
number = models.CharField("Patient's Number", max_length=12, unique=True)
class Appointment(models.Model):
to_number = models.ForeignKey(Number)
message = models.CharField("Message", max_length=160)
我希望Appointment
模型保留另一个字段,允许我添加用户希望在实际约会时间之前通过电子邮件收到通知的次数(类似于我们在 Google 日历中添加多个弹出/电子邮件通知的方式)。由于我还是 Web 开发、Django 和数据库模型的新手,我很难决定如何创建和链接模型来实现这一点。我想到的一个解决方案是创建另一个模型并将其链接起来,Appointment
如下所示:
class Notification(models.Model):
appointment = models.ForeignKey(Appointment)
time = models.TimeField("Time before appointment we must notify the user")
这甚至是明智的做法吗?如果没有,我应该怎么做?此外,为了通过管理控制台查看Appointment
和Notification
在Number
's 视图中,我应该声明什么内联堆栈(既然Number
--> Apppointment
--> Notification
,当在Number
's下查看时将它们链接为 Inline 的正确方法是什么?页)?我知道类似 [this has been ask before] ( Nested inlines in the Django admin? ),但自从 2010 年被问到,我很好奇是否有人找到了新的方法或者第二个答案@carruthd 在上述链接中仍然是最好的方法。谢谢你。