0

我有这样的习惯User model

class User(AbstractBaseUser):
    username = models.CharField(max_length=90, unique=True, db_index=True)
    create_time = models.DateTimeField(null=True, blank=True)
    update_time = models.DateTimeField(null=True, blank=True)
    email = models.CharField(max_length=225)
    external = models.IntegerField(null=True, blank=True)
    deleted = models.IntegerField(null=True, blank=True)
    purged = models.IntegerField(null=True, blank=True)
    form_values_id = models.IntegerField(null=True, blank=True)
    disk_usage = models.DecimalField(null=True, max_digits=16, decimal_places=0, blank=True)
    is_superuser = models.BooleanField()
    is_staff = models.BooleanField()
    is_active = models.BooleanField()
    date_joined = models.DateTimeField()
    objects = UserManager()
    USERNAME_FIELD = 'username'
    REQUIRED_FIELDS = ['email']
    class Meta:
        db_table = u'galaxy_user'

我已经为密码重置创建了所有必需的模板。我的应用程序名称是文件上传。因此,当我从 Django shell 执行此操作时,我会得到如下信息:

>>> from django.contrib.auth.models import User
>>> User.objects.all()
Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/usr/local/lib/python2.7/dist-packages/django/db/models/manager.py", line 256, in __get__
    self.model._meta.object_name, self.model._meta.swapped
AttributeError: Manager isn't available; User has been swapped for 'fileupload.user'
>>> 

如何使 Django 密码重置以在我的自定义用户模型上工作。谢谢

4

2 回答 2

0

你应该使用get_user_model

from django.contrib.auth import get_user_model
User = get_user_model()

User.objects.all()
于 2013-06-24T13:35:21.230 回答
0

我相信你需要添加

AUTH_USER_MODEL = <path_to_your_custom_User_model>

到你的项目settings.py

于 2020-07-10T23:53:16.737 回答