Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

seperate 'admin' interfaces for different user types in django

I have recently being trying to create a project which has several levels of user involved.

(Just an example of an abbreviated and rough schema)

  • ME (Super User)
    • Client(s)
      • Customer(s)
      • Survey Collections
        • SurveyUser(s)
          • Invitee(s)
        • Surveys
          • Invitee(s) (invitee is a child of both survey and user)
        • Questions
        • Etc

I would ideally have:

  • www.example.com/client/ go to a client interface which you had to be a client to access
  • www.example.com/customer/ go to a customer interface which you had to be a customer to access

I have already established that using a customised Django admin interface for all of them is probably not going to be possible (or is it?). I am therefore leaning towards manually creating 'admin' interfaces for each level of user, allowing them to manage their respective roles. What is the best way of having different user types and separate interfaces for each one?

I like the way of inheriting users outlined at: http://scottbarnham.com/blog/2008/08/21/extending-the-django-user-model-with-inheritance/

But am unsure how I would set up different 'admin' areas for different users.

As a side issue that is related, I am also unsure of how to access the custom properties alongside standard user properties and how to edit/save them in the ACTUAL admin interface that I will use.

I would need to authenticate 'Client' users against a client database to check they are clients but somehow also authenticate against the user database which manages authentication, username, password etc.

I am switching from PHP to Python/Django so any advice greatly appreciated to help me along.

Thanks!

like image 800
Pete Hamilton Avatar asked Mar 15 '11 20:03

Pete Hamilton


People also ask

How do you implement different types of users in Django?

For that case, you can use the built-in is_staff flag to differentiate normal users from admin users. Actually the built-in User model has two similar fields, is_staff and is_superuser . Those flags are used in the Django Admin app, the is_staff flag designates if the user can log in the Django Admin pages.

Can I have two user models in Django?

We can create multiple types of users which inherit from your base user model and they all can log in, authenticate, and perform different functions.

How do I restrict access to parts of Django admin?

Django admin allows access to users marked as is_staff=True . To disable a user from being able to access the admin, you should set is_staff=False . This holds true even if the user is a superuser. is_superuser=True .


1 Answers

The closest I got to this was based on another stackoverflow article here: How to have 2 different admin sites in a Django project?

I ended up creating two entirely separate instances of django.contrib.admin.sites.AdminSite which seemed to work in the end, albeit not ideal.

like image 84
Pete Hamilton Avatar answered Oct 09 '22 11:10

Pete Hamilton