django-xadmin后台人员添加新用户报错?
bobby老师,你好,我刚创建了一个django项目,把User表注册到xadmin后出现了以下问题:
django-xadmin给后台工作人员授权可以创建用户后,用该后台工作人员创建新用户报错:
File "/home/hhao/.virtualenvs/aftersales_env/lib/python3.7/site-packages/xadmin/util.py", line 311, in lookup_field value = getattr(obj, name) File "/home/hhao/.virtualenvs/aftersales_env/lib/python3.7/site-packages/django/db/models/fields/related_descriptors.py", line 535, in __get__ return self.related_manager_cls(instance) File "/home/hhao/.virtualenvs/aftersales_env/lib/python3.7/site-packages/django/db/models/fields/related_descriptors.py", line 848, in __init__ (instance, self.pk_field_names[self.source_field_name])) ValueError: "<User: >" needs to have a value for field "id" before this many-to-many relationship can be used.
这是我的User表
class User(AbstractUser): """用户模型类""" # mobile = models.CharField(max_length=11, unique=True, verbose_name='手机号') mobile = models.CharField( validators=[RegexValidator(regex="^\d{11}$", message="Length has to be 11", code="nomatch")], max_length=11, verbose_name="手机号") user_token = models.CharField(max_length=300, null=True, blank=True, verbose_name="用户认证token") default_address = models.OneToOneField('users.Address', related_name='user_addr', null=True, blank=True, on_delete=models.SET_NULL, verbose_name='默认地址') allow = models.BooleanField(default=False, verbose_name="是否同意用户协议") is_delete = models.BooleanField(default=False, verbose_name="是否删除")
这是为什么呢?User表中也没有字段名冲突啊,求教求教~~~~?
django 3.0.6
xadmin 2.0.1