如何在 Django 中存储有关用户的附加信息?
我有几个可以从我的 Django
应用程序向 用户
发送的通知。这些用户通过 django.contrib.auth 应用进行管理。
我需要跟踪每个用户是否指定他/她想要收到该通知。
我应该在哪里保存这些信息?
我本来打算创建自己的自定义表,但我发现也许我可以将该信息保存在 auth
模块中的某个位置?
I have several notifications that can be sent out from my Django
application for users
. These users are managed with the django.contrib.auth
app.
I need to keep track for each whether the user has specified he/she wants to get that notification.
Where should I save this information?
I was going to create my own custom table but I've seen perhaps I can save that information somewhere in the auth
module?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
用户个人资料是一个好方法。
https://docs.djangoproject.com/ en/dev/topics/auth/#storing-additional-information-about-users
为您的
User
对象设置一个带有OneToOneField
的模型,如下所述您可以轻松访问任意附加信息表。PS:请注意配置文件不会自动创建的事实。有一个关于如何使用信号在创建
User
时自动创建信号的示例。User Profiles are a good way to go.
https://docs.djangoproject.com/en/dev/topics/auth/#storing-additional-information-about-users
Set up a model with a
OneToOneField
to yourUser
object as described and you have easy access to an arbitrary table of extra information.PS: Heed the note about the fact that profiles are not automatically created. There is an example about how to use a Signal to automatically create one whenever a
User
is created.