且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

django外键(用户)在模型中

更新时间:2023-01-25 20:30:42

我不知道 settings.AUTH_USER_MODEL方法,但是众所周知常用的方法是 Auth.User模型。

I do not know the "settings.AUTH_USER_MODEL" approach but a well-known approach and commonly used is the "Auth.User" model. Something like this on your end.

from django.contrib.auth.models import User

class BlogPost(models.Model):
    '''a model for a blog post'''

    author = models.ForeignKey(User)
    date = models.DateField()
    title = models.CharField(max_length=100)
    post = models.TextField()