Role based access

15 views
Skip to first unread message

Doddahulugappa.B

unread,
Jan 19, 2020, 4:34:59 AM1/19/20
to django...@googlegroups.com
Hi team,

How to make role based access in django. For ex. 

If employee names and their department in one table.

 And also we assign department to user. With manytomany field.. So how can i display only the records of employees and their department which is assigned to the user. 

Kindly help.. 

Nitin Kalmaste

unread,
Jan 19, 2020, 5:02:26 AM1/19/20
to django...@googlegroups.com
You can assign django groups from user model as department and give special permission to that group

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAKfjjGpT_xeQaRqySC4SX_v2-aVOb7u5%2B9qoPhByQ8Wq2DM4ow%40mail.gmail.com.

maninder singh Kumar

unread,
Jan 19, 2020, 5:10:09 AM1/19/20
to django...@googlegroups.com
Could it be that there is a user from each department and each user in a department has a role ? 
 
               
 


Doddahulugappa.B

unread,
Jan 19, 2020, 5:19:12 AM1/19/20
to django...@googlegroups.com
Thank you for your response. Can you please Explain me how to do that.. 

maninder singh Kumar

unread,
Jan 19, 2020, 5:46:44 AM1/19/20
to django...@googlegroups.com
Django has an authentication model of :
1. Creating users
2. Assigning them permissions or group permissions

Use Authenticate() to authenticate users.  Based on the assigned permissions they will have access to parts of your site.  Basically you create views and the objects in the views are available to users with permissions.  For example :

def myview(request)
                                             #My users database has a user 'Guy" with password "1234"
myuser = users_Users.object.values("users_Name').filter(users_Name_starts_with = "Guy")
                                             #Permissions for this object can be set.
myuser.has_view_permission('foo.bar')
myuser.has_add_permission('foo.bar')   
myuser.has_delete_permission('foo.bar')    #where foo is the application and bar the model
object_list = Content.objects.all()

HULUGESH B

unread,
Jan 19, 2020, 6:02:57 AM1/19/20
to django...@googlegroups.com

My use case is like this

 

name

age

department

user(manytomanyfiled)

xyz

23

cs

user1

abc

24

ec

user1

pqr

25

me

user2

 

 

Now my question is if user1 loged in means he has to see only

 

name

age

department

user(manytomanyfiled)

xyz

23

cs

user1

abc

24

ec

user1

 

And if user2 login means

name

age

department

user(manytomanyfiled)

pqr

25

me

user2

 

 

Kindly let me know below explanation is serving my purpose?

 

Best Regards,

HULI

 

From: maninder singh Kumar
Sent: Sunday, January 19, 2020 2:46 PM
To: django...@googlegroups.com
Subject: Re: Role based access

 

Django has an authentication model of :

1. Creating users

2. Assigning them permissions or group permissions

 

Use Authenticate() to authenticate users.  Based on the assigned permissions they will have access to parts of your site.  Basically you create views and the objects in the views are available to users with permissions.  For example :

 

def myview(request)

                                             #My users database has a user 'Guy" with password "1234"

myuser = users_Users.object.values("users_Name').filter(users_Name_starts_with = "Guy")

                                             #Permissions for this object can be set.

myuser.has_view_permission('foo.bar')
myuser.has_add_permission('foo.bar')   

myuser.has_delete_permission('foo.bar')    #where foo is the application and bar the model

object_list = Content.objects.all()

 


 

 

Maninder Kumar

 

               

 

 

 

On Sun, Jan 19, 2020 at 3:49 PM Doddahulugappa.B <doddahu...@gmail.com> wrote:

Thank you for your response. Can you please Explain me how to do that.. 

 

On Sun, Jan 19, 2020, 2:09 PM maninder singh Kumar <maninder...@gmail.com> wrote:

Could it be that there is a user from each department and each user in a department has a role ? 

 

 

Maninder Kumar

 

               

 

 

 

On Sun, Jan 19, 2020 at 3:04 PM Doddahulugappa.B <doddahu...@gmail.com> wrote:

Hi team,

 

How to make role based access in django. For ex. 

 

If employee names and their department in one table.

 

 And also we assign department to user. With manytomany field.. So how can i display only the records of employees and their department which is assigned to the user. 

 

Kindly help.. 

 

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAKfjjGpT_xeQaRqySC4SX_v2-aVOb7u5%2B9qoPhByQ8Wq2DM4ow%40mail.gmail.com.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CABOHK3TS62AWZLjR48m%2BzG%3DgWouvCQfY90KcpMAsMD_T%3DoOW1A%40mail.gmail.com.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAKfjjGqsW_FUKhEoEn4fxBR46sdF-xFhct864J_cmp-EjbbUeg%40mail.gmail.com.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.

maninder singh Kumar

unread,
Jan 19, 2020, 7:30:04 AM1/19/20
to django...@googlegroups.com
it will work, it requires working out queries
 
               
 


Doddahulugappa.B

unread,
Jan 19, 2020, 7:56:07 AM1/19/20
to django...@googlegroups.com
Thank you. I ll check it out. 

maninder singh Kumar

unread,
Jan 19, 2020, 8:39:13 AM1/19/20
to django...@googlegroups.com
Here's what you could do :

def requestView(request):

      

say :

first_query =<yourModel>.objects.values_list(‘name’, age’, ‘department’, ‘user’).filter(user__icontains = ‘user1’)


       second_query = <yourmodel>.objects.values_list(‘name’, age’, ‘department’, ‘user’).filter(user__icontains = ‘user1’)

   

#the below part can be worked out using django docs

    -------

      myuser.groups.set([group_list])

     view: user.has_perm('<your app>.view_<yourModel>')

   -----------

return render (request=request, template_name='template.html', context = {text1 : first_query, text2 : second_query})


{{first_query.name}}





 
               
 


On Sun, Jan 19, 2020 at 4:32 PM HULUGESH B <doddahu...@gmail.com> wrote:

Doddahulugappa.B

unread,
Jan 19, 2020, 9:50:34 AM1/19/20
to django...@googlegroups.com
Thank you so much. I will try this.. 

Reply all
Reply to author
Forward
0 new messages