self.field.rel.to.DoesNotExist when trying to access user through model

后端 未结 1 812
情歌与酒
情歌与酒 2021-01-14 19:59

I am trying to extend my model to include User but without much luck.

from django.db import models
from django.contrib.auth.models import User

class Tes         


        
1条回答
  •  执笔经年
    2021-01-14 20:56

    You are not passing a User instance to your class TestModel:

    do something like this:

    from django.contrib.auth.models import User
    
    us = User.objects.all()[0]
    t = TestModel(user=us)
    t.save()
    print t
    

    0 讨论(0)
提交回复
热议问题