I'm working a project wherein there are multiple institutions. All the institutes have the same hierarchy of students, teachers and staff members. My problem is how do I keep the institutions apart? For example: the data profile of student from institute A should not be editable by a staff member in institute B. And vice versa. I'm able to use AbstractUser class to give my own roles but what about users (like Staff Members) who have the same permissions but shouldn't interfere with other institutions?
Asked
Active
Viewed 65 times
0
-
django-guardian can help you achieve this with one database, you need to create one group per institution and add that group permission for the record not table – Naqib Hakimi Dec 18 '19 at 19:59
1 Answers
0
Django allows you to use multiple databases as illustrated in the docs. You can use a separate database for each intitue and set your database router to direct you to the right db based on some attribute in the user profile.
An example of this process is available here

m0etaz
- 953
- 1
- 8
- 21
-
This is an interesting solution. And how about superusers? I mean users who can see/edit virtually all data? So I can keep a separate database for those folks as well? – Mithil Bhoras Dec 18 '19 at 19:41
-
but a superuser in institution A shouldn't be able to edit data of institution B, right? so you can treat them like all other users. – m0etaz Dec 18 '19 at 19:58
-
Right. But there is a scenario (apologies I didn't mention) where a super-super user will over see all the institutions. What to do in this case? – Mithil Bhoras Dec 18 '19 at 20:02
-
In that case you can create a custom manager that queries the multiple databases and concatenates the results for these people. I'm not sure that's an optimal solution though. c.f. https://docs.djangoproject.com/en/3.0/topics/db/multi-db/#using-get-queryset-with-multiple-databases – m0etaz Dec 18 '19 at 20:09