我有一个模型subscription
,其中的类定义如下,
class Subscription(TimestampedModel):
...
notification = models.ForeignKey(
'settings.NotificationPreference', on_delete=models.SET(get_default_reminder), null=True
)
...
如果要删除外部模型,我想设置default notification: id
,经过研究发现,可以使用https://docs.djangoproject.com/en/2.1/ref/models/fields/#django.db.models.SET的set
方法,我参考了it was using TypeScript's Module Resolution behaviour实施,但是我现在陷入困境,因为默认通知将基于每个用户。我的get_default_reminder
函数如下所示,
def get_default_reminder():
return NotificationPreference.objects.get(user_id=user_id, name='Default Notification')
这里的问题是我不明白如何传递user_id
来获取用户特定的默认通知ID。