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.