1👍
✅
Here it is:
app = apps.get_app_config('school')
for model_name, model in app.models.items():
model_admin = type(model_name + "Admin", (admin.ModelAdmin, ), {'list_display': tuple([field.name for field in model._meta.fields])})
admin.site.register(model, model_admin)
0👍
Apologies as i haven’t checked this. But i think get_all_field_names()
method should be able to get this.
I think you might be able to use it in this way: [field.name for field in MyModel._meta.get_fields()]
. But this is deprecated from django 1.8. Might work for now but it will be discontinued in future.
Sorry couldn’t comment on your question due to insufficient reputation.
Source:stackexchange.com