Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django Get All Users

Tags:

python

django

I am just starting out with Django and I am messing around just trying to pull a full list of users from postgres.

I used the following code:

group = Group.objects.get(name="Admins") usersList = group.user_set.all() 

How could you pull all users? I don't want to have to pick or assign a group.

group = Group.objects.get() #Doesn't Work. usersList = group.user_set.all() 
like image 532
Adam Avatar asked Apr 17 '14 17:04

Adam


People also ask

How do I fetch all users in Django?

Django get user it's also simple method to get all user ,create user ,change password ,etc. Show activity on this post. all_users will contain all the attributes of the user. Based upon your requirement you can filter out the records.

What is Is_authenticated in Django?

For Django 1.10 + As Richard mentioned is_authenticated is a function, so in your view it should be called like: request. user. is_authenticated() . Because of django templating language there can be confusion, because calling this in a template makes it appear as a property and not a method.

What is Is_active in Django?

is_active. Boolean. Designates whether this user account should be considered active. We recommend that you set this flag to False instead of deleting accounts; that way, if your applications have any foreign keys to users, the foreign keys won't break.

What is Is_staff in Django?

Those flags are used in the Django Admin app, the is_staff flag designates if the user can log in the Django Admin pages. Now, what this user can or cannot do, is defined by the permissions framework (where you can add specific permissions to a given user, e.g. can create/update users but cannot delete users).


2 Answers

from django.contrib.auth import get_user_model User = get_user_model() users = User.objects.all() 
like image 65
Brandon Avatar answered Sep 21 '22 20:09

Brandon


Django get user it's also simple method to get all user ,create user ,change password ,etc

from django.contrib.auth import get_user_model user = get_user_model() user.objects.all() 
like image 38
Harish Verma Avatar answered Sep 20 '22 20:09

Harish Verma