django-users

How to update User model in Django using signals.py

How to update User model in Django using signals.py Question: how can I update the user model first_name and last_name in Django using signals.py when a new user updates first_name and last_name in custom registration form? This is my signals.py for creating a custom separate user details model using Django @receiver(post_save, sender=settings.AUTH_USER_MODEL) def create_profile_handler(sender, instance, …

Total answers: 1

Django: Custom User Model with Autoincrementing Id

Django: Custom User Model with Autoincrementing Id Question: I am trying to use Django Authentication and I want to create a custom model for the user that has an autoincrementing integer as id. I know about uuid library, but I want the id to be an integer number, that is why I want to avoid …

Total answers: 1

Django authenticate() command returns None

Django authenticate() command returns None Question: I am doing a website which has Google sign in and I am trying to log in the user when they click the sign in with Google button. This is the code that doesn’t work: def google_login(request): # Some irrelevant code here try: obj = GoogleSignupToLoginSecurityKey.objects.get(email=email) user = authenticate(email=email, …

Total answers: 1

How to create users in Django?

How to create users in Django? Question: I am trying to use Django’s user model, but when I cannot create a new user. I already ran python manage.py makemigrations and python manage.py migrate. If I try to run the commands again, I get a "No Changes Detected" message. I was able to create a superuser …

Total answers: 3

How to create a Django superuser if it doesn't exist non-interactively?

How to create a Django superuser if it doesn't exist non-interactively? Question: I want to automate creation of Django users via a Bash script. I found this snippet which almost suits my needs: echo “from django.contrib.auth.models import User; User.objects.create_superuser(‘admin’, ‘[email protected]’, ‘pass’)” | python manage.py shell How can I modify it so that it’s a nop …

Total answers: 4

Django: ImportError: cannot import name 'User'

Django: ImportError: cannot import name 'User' Question: I’m new to django and I’m facing some difficulties in creating a user from the AbstractBaseUser model. Now I’m starting wondering if my user model is not being build in the right way. This is my User model from django.db import models from django.contrib.auth.models import AbstractBaseUser class User(AbstractBaseUser): …

Total answers: 6

Difference between AbstractUser and AbstractBaseUser in Django?

Difference between AbstractUser and AbstractBaseUser in Django? Question: The use of AbstractUser and AbstractBaseUser looks quite similar. from django.contrib.auth.models import AbstractUser, AbstractBaseUser What is the difference between the two? Asked By: Pranjal Mittal || Source Answers: The documentation explains this fully. AbstractUser is a full User model, complete with fields, as an abstract class so …

Total answers: 5

How to use 'User' as foreign key in Django 1.5

How to use 'User' as foreign key in Django 1.5 Question: I have made a custom profile model which looks like this: from django.db import models from django.contrib.auth.models import User class UserProfile(models.Model): user = models.ForeignKey(‘User’, unique=True) name = models.CharField(max_length=30) occupation = models.CharField(max_length=50) city = models.CharField(max_length=30) province = models.CharField(max_length=50) sex = models.CharField(max_length=1) But when I run …

Total answers: 2

request.user returns a SimpleLazyObject, how do I "wake" it?

request.user returns a SimpleLazyObject, how do I "wake" it? Question: I have the following method: def _attempt(actor): if actor.__class__ != User: raise TypeError Which is called from a view: self.object.attempt(self.request.user) As you can see, the _attempt method expects actor to be type django.contrib.auth.models.User, however the object appears to be of type django.utils.functional.SimpleLazyObject. Why is this …

Total answers: 7

How to customize the auth.User Admin page in Django CRUD?

How to customize the auth.User Admin page in Django CRUD? Question: I just want to add the subscription date in the User list in the Django CRUD Administration site. How can I do that ? Thank you for your help Asked By: Natim || Source Answers: Assuming that your user class is User and your subscription …

Total answers: 4