I am creating a data entry app and started with one site, mainly numerical data having quite complex forms. I rely on Django-Admin for the site manager to edit reference data and review/change entered data in case something is not right.
The first site has about 10 applications and it works not bad. Now I want to branch out and add another similar site. This leads to a question about organization: I could copy paste all the relevant apps and adapt/change them into a new site. This would be easier initially but will lead to headaches further down the road.
I currently control site access via bootstrap-buttons with user-permissions.
How would an experienced django-developer recommend to organize such an application, where I would be able to:
to manage site-based admin-access
allow each site having their own reference data
manage form-permissions where users from one site can only see/enter data for one site…
after researching a bit further: neither the built-in sites nor django-tenants seems to be what I would need;
I have one application within one domain
I want to allow individual users from specific locations to only edit their respective data (separate data rather than webpages)
I want to reduce code repetition by rather writing one form for multiple similar locations (instead of copying the apps multiple times)
So, I would probably need to integrate a new location table and link it to user permissions.
Quite a few things are unclear, e.g. how this can be also translated to the admin page (for location managers) and how to handle page deviations from the “standard”.
Instead of writing a big app for each location, I probably will need apps for similar processes and limit their respective scope through the user model.
Solving this issue effective requires knowing exactly what the differences are between sites and how those differences can be handled on a per-user basis.
(I’m assuming that all users are authenticated, so that you have some means of identifying which particular set of customizations are presented.)
I’ll start out by pointing out that these requirements;
… It reads metadata from your models to provide a quick, model-centric interface where trusted users can manage content on your site. The admin’s recommended use is limited to an organization’s internal management tool. It’s not intended for building your entire front end around.
… If you need to provide a more process-centric interface that abstracts away the implementation details of database tables and fields, then it’s probably time to write your own views.
Handling row-level security within the admin is possible, but it’s actually easier to do it within your own views. Yes, there are relatively easy ways to cover the “90% case” with the admin, but that remaining 10% is going to give you massive headaches. Over time, you are more likely to find it taking longer to customize the admin than the time required to produce a view.
By creating your own views, you’re able to more easily control exactly what a person sees.
So, concerning the admin: I don’t want to build the front-end around it :-).
Roughly intended admin use cases:
Basic users should enter data (no admin access).
Site managers should be able to:
1. edit entered data of their users
2. modify reference data (vehicles, etc) of their respective sites (without affecting or seeing other sites).
In addition, there are (max 2) master-admins, that should be able to see and edit everything.
Creating views for editing all the models would be possible later on, but for now I was hoping to simply leverage the admin-functionality for a selected user-base.
Solving this issue effective requires knowing exactly what the differences are between sites and how those differences can be handled on a per-user basis.
(I’m assuming that all users are authenticated, so that you have some means of identifying which particular set of customizations are presented.)
The application will grow with additional sites; at the current stage it is impossible to gather all the requirements down the hill, it is also depending on a lot of soft factors such as user acceptance how many sites are getting connected. But the main idea is, that sites of similar type will get a very similar interface (except for some additional fields in some cases).
I hoped to avoid preparing views with prefilled data, these formsets are a bit difficult to work with, particularly, if data is edited and sent back. Editing entered data is one part of the application (and hopefully not needed often), but definitely not the core part.
Create your own views for the site managers. It’s going to be easier to ensure that they can only view/edit the data you want them to be able to.
What is the issue with granting admin access to 3-5 key users? I did read about issues with list views. It would add a significant amount of development time to include proper views of all models (with rowlevel-security), I hoped to save time here and leverage the quite well established django admin interface.
There isn’t one - provided you’re using the admin as designed and intended.
The issues start arising as you start customizing it to provide “application-specific” features that go beyond what the admin was designed to support.
It’s a very appealing path, until you hit a limitation where the admin won’t quite do what you need it to. You can then find yourself spending a lot of time and effort trying to resolve something - and may yourself come to the conclusion that it would have been easier to do this in a view.
It’s a pattern that multiple people have seen many times through the years.
Now, it’s not an absolute. Your needs may not lead you into that situation.
But, the admin was never designed around supporting row-level security. I have seen various snippets showing how it can start to be implemented, but I can’t say that there aren’t “holes” where information would be leaked. That’s something only you will be able to determine.
If you know you’re going to be ok with a 90% solution, then you’re probably fine - because in that situation you are making the judgement that you trust the site managers with the possibility of seeing other site’s data.
But in our case, that assumption was a non-starter. We had to ensure that the data was segregated between organizations - and I knew that the admin couldn’t be trusted for that.
It may or may not. (What you don’t know yet is how much time it will take to secure the admin to properly support row-level security and test / validate it to a degree you consider acceptable.)
Creating a number of views is not as difficult as you seem to imply. Once you’ve started to identify certain patterns and implementation features, you may find that developing your own class-based views library yields a lot of benefits.