django foreignkey(user) in models

后端 未结 4 1155
臣服心动
臣服心动 2020-12-31 00:23

I read the docs and this post... Django - Foreign Key to User model

I followed what it said and I still cannot get it to work. When I try to run the migrations I get

4条回答
  •  南笙
    南笙 (楼主)
    2020-12-31 00:51

    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()
    

提交回复
热议问题