Skip to content

Instantly share code, notes, and snippets.

@leisurelicht
Last active October 25, 2023 00:46
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save leisurelicht/ad469c23e90c856e69075585ed40f1db to your computer and use it in GitHub Desktop.
Save leisurelicht/ad469c23e90c856e69075585ed40f1db 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