I want to implement some logic to hide some objects via Django Admin. This will hide few instances from list of Django Model object.
Please advise how I should approach this? Let me know if you need info?
I want to implement some logic to hide some objects via Django Admin. This will hide few instances from list of Django Model object.
Please advise how I should approach this? Let me know if you need info?
You can use a ModelAdmin List Filter to allow the user to limit what they see, but it’s an exceedingly bad idea to hide anything completely in the Admin.
If you think it’s necessary to do that, then you’re using the Admin in a way that it was never intended to be used. Review the first two paragraphs at The Django admin site | Django documentation | Django.
Thanks Ken for your advise. What about disabling these instances instead? That’s prevent someone to open detail view of these instances
You can use the ModelAdmin.has_* methods to perform by-object permission tests for users attempting to access specific objects.
See the docs starting at ModelAdmin.has_view_permission for the different methods you can implement in your ModelAdmin class to restrict access to specific objects or models by user.
Thanks again, Ken. Using the ModelAdmin.get_queryset method, I was able to achieve my goal.
I believe I have a good use case for this: I am using django-adfs-auth and single-signon and I wish to hide the user password field.
This seems to me to be a slightly different case - it’s not that you’re trying to prevent some users from seeing other users, but that you don’t want any user to see the User password field - am I understanding this correctly?
If so, this is a different issue. In this situation you would need to:
I can’t speak to the similarity but your suggestion worked for me, @KenWhitesell I had actually already done most of those things except remove the password field from the list and when I did it was hidden.