0

I need to have bootstrap css in django admin, but only in change view, not list view. If I use

    class Media:
    css = {
        'all': ('tagsinput/bootstrap-tagsinput.css', 'bootstrap-3.3.7-dist/css/bootstrap.css',)
    }

It affects both views and breaks some elements in list view. How can I do that?

3
  • If the answer is good, please mark it as accepted. Commented Jun 21, 2019 at 9:46
  • It works, but I'm searching for a better solution. Overriding a template affects all adminModels, but I want to have that css only in one adminModel's changeView Commented Jun 21, 2019 at 12:19
  • If you check that link from django documentation you will see you can have it for specific model. You did not share the model path of your code but let's say your model named FooModel is in package Foo, the correct path would be {templates_dir}/admin/foo/foomodel/change_list.html Commented Jun 21, 2019 at 14:40

1 Answer 1

1

Easiest way is to override change_list template by your own. Create folder called admin in your templates folder. Then if you want to have it global effect, create change_list.html file there.

{% extends "admin/change_list.html" %}
{% block extrastyle %}
    {{ block.super }}
    <link rel="stylesheet" type="text/css" href="{% static "/css/your_style.css" %}">
{% endblock %}

EDIT: If you have model FooModel in package Foo, where you want to apply this css, place the file to {template_dir}/admin/foo/foomodel/change_list.html, if you want it for whole package {template_dir}/admin/foo/change_list.html

Sign up to request clarification or add additional context in comments.

1 Comment

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.