Django Admin Page

January 24th, 2020   プログラミング  Django

I wanted to change the list of items in the Post model on the Django Admin page. I created a class in admin.py and tried to register the model, but I couldn't register. The cause was that registration was duplicated because the Post model had already been registered with Markdownx.

I want to use Markdownx, so I checked for other methods. There was a way to inherit and override the model by "proxy model".

There were other methods such as creating a custom template, but it was good that using proxy model was easy way.

Reference sites


Reference codes


model.py

# Admin画面の項目並びで利用
class PostProxy(Post):

    class Meta:
        proxy = True

admin.py

"""
class PostAdmin(admin.ModelAdmin):
    list_display = ("title", "title_en", "category", "published_date")
"""

admin.site.register(Category)
admin.site.register(Tag)
""" admin.site.register(Post, PostAdmin) """
admin.site.register(Post, MarkdownxModelAdmin)
admin.site.register(Comment)

@admin.register(PostProxy)
class PostProxyAdmin(admin.ModelAdmin):
    list_display = ("title", "title_en", "category", "published_date")

Reference image


Sponsor Link