Skip to content

Instantly share code, notes, and snippets.

@cansadadeserfeliz
Created October 9, 2014 17:05
Show Gist options
  • Select an option

  • Save cansadadeserfeliz/d028f7c1f76563a06b8e to your computer and use it in GitHub Desktop.

Select an option

Save cansadadeserfeliz/d028f7c1f76563a06b8e to your computer and use it in GitHub Desktop.
Make all fields readonly for Django Admin
class StudentAnswersAdmin(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