Skip to content

Instantly share code, notes, and snippets.

@quevon24
Forked from leisurelicht/admin.py
Created January 6, 2023 16:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save quevon24/b42691d1271a61b40c47a689ffdd1b5f to your computer and use it in GitHub Desktop.
Save quevon24/b42691d1271a61b40c47a689ffdd1b5f to your computer and use it in GitHub Desktop.
Make all fields readonly for Django Admin
class OpsIPInfoAdmin(admin.ModelAdmin):
def get_readonly_fields(self, request, obj=None):
# make all fields readonly
readonly_fields = list(
set([field.name for field in self.opts.local_fields] +
[field.name for field in self.opts.local_many_to_many])))
if 'is_submitted' in readonly_fields:
readonly_fields.remove('is_submitted')
return readonly_fields
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment