How to fix/set column width in a django modeladmin change list table when a list_filter is added?

前端 未结 2 473
忘了有多久
忘了有多久 2020-12-16 21:34

I\'m working on improving the admin.py in a django project, and while I\'m not totally jazzed about how the table was coming out with three fields in the list_diplay, at lea

相关标签:
2条回答
  • 2020-12-16 22:17

    You may want to refer to this: https://docs.djangoproject.com/en/dev/ref/contrib/admin/#overriding-vs-replacing-an-admin-template

    basically, the change_list.html needs to be overridden .

    you can do it this way:

    templates/
      admin/
        app/
          change_list.html
    

    you can obtain a copy of change_list.html from django/contrib/admin/templates/admin/

    and update the css the way you desire.

    0 讨论(0)
  • 2020-12-16 22:30

    admin.py:

    class MyClassAdmin(admin.ModelAdmin):
    
        class Media:
            css = {
                'all': ('fancy.css')
            }
    

    fancy.css:

    .column-foo {
        width: 20px;
    }
    

    where "foo" is a field name.

    Source: https://docs.djangoproject.com/en/3.0/topics/forms/media/

    0 讨论(0)
提交回复
热议问题