I'm currently building a Hospital Management system with Django but encountered an issue. In this website, admins will register for their respective hospitals and manage their doctors, patients etc. But, I don't want one hospital's admin to see the informations of ther hospitals' doctors or patients. So how can I make sure that the admin only sees the data of his own hospital and not others'. What changes can I make in my models to do so?
Asked
Active
Viewed 43 times
0
-
Does this answer your question? [How to limit queryset/the records to view in Django admin site?](https://stackoverflow.com/questions/2279313/how-to-limit-queryset-the-records-to-view-in-django-admin-site) – Stevy Jun 03 '20 at 12:45
1 Answers
0
If you are asking about using Django Admin module, I think that you sooner or later will find out that you need to do this outside of Django Admin, which is powerful, but it has it's own limitations. It is a handy tool that is more than adequate for your own admin stuff, but it is not intended (I believe) to be used by many admins for their regular stuff.
That said you will have to decide how to handle separation in your app. It is not easy task and you will need to take extra precaution to separate things between them. One of the solutions is to have separate databases for separate hospitals, other solution is to have all in same database and separate data programatically. It is really up to you to decide.

Branko Radojevic
- 660
- 1
- 5
- 14
-
I'm actually doing this outsite the built-in django admin. But, how can separate the data programatically? I mean do I need to use queryset or something like that? – Imran Rahman Jun 03 '20 at 13:54
-
I use additional fields in every model that needs to be separated, if the fields are not already there. For example, if it is separated by hospital, then you need to add field hospital that will be probably ForeignKey to hospital model to all models that require separation. Than, you will need to add this field to all querysets so that every admin gets only records that are set with this field to his hospital. A little bit of extra programming is needed, but it is a possible way how to do it. – Branko Radojevic Jun 03 '20 at 14:14