3 ms·
The thing that's killing me w/ Django's Admin system is there's no concept of pure Viewing data. A big part of administering your end users is having staff be
by irjustin 4y ago
The thing that's killing me w/ Django's Admin system is there's no concept of pure Viewing data.
A big part of administering your end users is having staff be able to "see" what is going on w/ the user (i.e. a dashboard for user and all user related objects, like what company they belong to, money, products, purchases etc). But it's weird that the viewing page is also the editing page.
- reubenmorais 4y agoYou can give staff users limited privileges, such as view only.
- irjustin 4y agoThe goal isn't to give staff view only. It's to separate the viewing and editing.
- simonw 4y agoOnce you figure out how to do it the Django admin actually has really neat support for read-only views of data. The trick is to implement these methods on your ModelAdmin subclass: https://docs.djangoproject.com/en/4.1/ref/contrib/admin/#django.contrib.admin.ModelAdmin.has_add_permission https://docs.djangoproject.com/en/4.1/ref/contrib/admin/#dja... You can make has_add_permission(), has_change_permission() and has_delete_permission() all return False, while has_view_permission() returns True. The readonly_fields and related get_readonly_fields() method are very useful too. I wrote up another related trick in this TIL: https://til.simonwillison.net/django/extra-read-only-admin-information https://til.simonwillison.net/django/extra-read-only-admin-i...
- irjustin 4y agoThanks, but the goal isn't to prevent editing. It's to prevent accidental editing. Staff need to be able to change things but 95% of the time they're simply viewing data to help answer questions, etc.
- simonw 4y agoYou can do that too with some more tricks. It's possible to register more than one ModelAdmin for a given model - so you could have a read only one which staff spend most of their time in, but that then links to the writable one when they need to make changes. You could even register multiple admin sites: /admin/ showing read-only data and /admin-write/ that allows it to be edited.