TypeError: all() missing 1 required positional argument: 'self' while using AbstractUser model
class User(AbstractUser):
nickname = models.CharField(max_length=32)
birthday = models.DateField()
objects = MyUserManager
class Meta:
ordering = ('-id',)
I created an custom user model and defined the MyUserManager class to manage the model.
class MyUserManager(UserManager):
def _create_user(self, username, email, password, **kwargs):
if not username:
raise ValueError("The given username must be set")
user = self.model(email=self.normalize_email(email), **kwargs)
user.set_password(password)
user.save()
return user
def create_user(self, username, email=None, password=None, **kwargs):
kwargs.setdefault('is_admin', False)
return self._create_user(username, email, password, **kwargs)
def create_superuser(self, username, email=None, password=None, **kwargs):
kwargs.setdefault("is_staff", True)
kwargs.setdefault('is_admin', True)
return self._create_user(username, email, password, **kwargs)
I was going to create a createuser/createsuperuser function that receives values for the custom fields as parameters. However, first of all, I would like to resolve the errors that have occurred now.
class UserViewSet(ModelViewSet):
queryset = User.objects.all()
serializer_class = UserSerializers
This is views.py in account app and error have occured in this code. Why can't I find a self instance? What instance does the original User.objects return? Is there a problem with the MyUserManager class?
Try adding parentheses in front of myusermanager in your user model like:
objects = MyUserManager()