Excellent explanations.
I ran into the same problem of populating Django admin for a legacy database. I ended up using mixin and type can populate the entire admin with relevant columns.
mixin
type
class ListAdminMixin(object): def __init__(self, model, admin_site): self.list_display = [field.name for field in model._meta.fields if field.name != "id"] super(ListAdminMixin, self).__init__(model, admin_site)
models = apps.get_models() for model in models: admin_class = type('AdminClass', (ListAdminMixin, admin.ModelAdmin), {}) try: admin.site.register(model, admin_class) except admin.sites.AlreadyRegistered: pass
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Excellent explanations.
I ran into the same problem of populating Django admin for a legacy database. I ended up using
mixin
andtype
can populate the entire admin with relevant columns.