Questions tagged [django-users]

User model is the default model in Django. It provides many APIs which are helpful for working with users. Django user model is overridable in a Project according to required field.

Django(a high-level Python Web framework) comes with a user authentication system. It handles user accounts, groups, permissions and cookie-based user sessions.

894 questions
26
votes
2 answers

How to check current user's permissions from a Group in Django?

I have a group EuropartsBuyer and model named Product. The following code adds a permission to the Product model. class Meta: permissions = ( ("can_add_cost_price", "Can add cost price"), ) In one of my views I have the…
MiniGunnR
  • 5,590
  • 8
  • 42
  • 66
26
votes
2 answers

setting expiration time to django password reset token

I am using the inbuilt password reset functionality of Django which emails the user the password reset link. Is there an option in Django to set an expiration time to the link suppose 6 hours after which the link become invalid and user will have to…
Sar009
  • 2,166
  • 5
  • 29
  • 48
24
votes
4 answers

django custom user model password is not being hashed

I have my own custom User model, and its own Manger too. models: class MyUser(AbstractBaseUser, PermissionsMixin): email = models.EmailField(max_length=255, unique=True) first_name = models.CharField(max_length=35) last_name =…
23
votes
4 answers

How do I inline edit a django user profile in the admin interface?

If you want to store extra information about a user (django.contrib.auth.models.User) in Django you can use the nifty AUTH_PROFILE_MODULE to plug in a "profile" model. Each user then gets a profile. It's all described…
André Laszlo
  • 15,169
  • 3
  • 63
  • 81
23
votes
2 answers

Working with user roles in Django

I have some question In a project I have the need of work with users which are of three (may be more) types of them have different roles: physician patient administrator I have been thinking use of the Django Model Users and extend it creating a…
bgarcial
  • 2,915
  • 10
  • 56
  • 123
23
votes
1 answer

FieldError at /admin/ - Unknown field(s) (added_on) specified for UserProfile

I'm using a custom user model in Django. The model works fine and is able to create a user. But when I try to access the admin page it throws me the error FieldError at /admin/ Unknown field(s) (added_on) specified for UserProfile The UserProfile…
user3725362
  • 509
  • 2
  • 4
  • 13
23
votes
5 answers

How do I prevent permission escalation in Django admin when granting "user change" permission?

I have a django site with a large customer base. I would like to give our customer service department the ability to alter normal user accounts, doing things like changing passwords, email addresses, etc. However, if I grant someone the built-in…
David Eyk
  • 12,171
  • 11
  • 63
  • 103
22
votes
5 answers

Get current user log in signal in Django

I am just using the admin site in Django. I have 2 Django signals (pre_save and post_save). I would like to have the username of the current user. How would I do that? It does not seem I can send a request Or I did not understand it. Thanks
Djanux
  • 301
  • 1
  • 4
  • 10
20
votes
7 answers

Django 1.5 custom User model error. "Manager isn't available; User has been swapped"

I extend the django user model as described in the dev doc. I wan't to keep most of the original User model features so I extend the AbstractUser class. I've defined in settings.py: AUTH_USER_MODEL = 'myapp.CustomUser' My user class: class…
nulse
  • 862
  • 1
  • 8
  • 18
18
votes
2 answers

Checking if a Django user has a password set

I setup if statement to see if the current user has a password set. For some reason it just won't work. I have tried: {% if not user.password %} {% if user.password == None %} {% if user.password is None %} I have 2 user accounts (different…
Designer023
  • 1,902
  • 1
  • 26
  • 43
17
votes
4 answers

Multiple USERNAME_FIELD in django user model

My custom user model: class MyUser(AbstractBaseUser): username = models.CharField(unique=True,max_length=30) email = models.EmailField(unique=True,max_length=75) is_staff = models.IntegerField(default=False) is_active =…
Saurabh Verma
  • 6,328
  • 12
  • 52
  • 84
17
votes
2 answers

Extending User object in Django: User model inheritance or use UserProfile?

To extend the User object with custom fields, the Django docs recommend using UserProfiles. However, according to this answer to a question about this from a year or so back: extending django.contrib.auth.models.User also works better now -- ever…
Chris
  • 1,632
  • 2
  • 16
  • 22
16
votes
1 answer

self.model() in django custom UserManager

So, I'm fairly new to Django. Notwithstanding the fact that my code works after following the Django docs 'Customizing authentication in Django', I don't get how the self.model(...) in their example actually works, where it comes from and how it…
15
votes
4 answers

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

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', 'admin@example.com', 'pass')" |\ python…
planetp
  • 14,248
  • 20
  • 86
  • 160
15
votes
3 answers

using User.objects.get_or_create() gives invalid password format in django?

python manage.py shell >>> from django.contrib.auth.models import User >>> u=User.objects.get_or_create(username="testuser2",password="123") >>> u (, True) seems it created the User properly. but when I logged into admin at…
brain storm
  • 30,124
  • 69
  • 225
  • 393
1
2
3
59 60