Search code examples
djangodjango-admin

Django DateTimeField show Date and Time input in the same line in admin


Suppose I have a model with DateTimeField.

And for DateTimeField, currently admin input is:

enter image description here

Is it possible to customize it to enter image description here


Solution

  • You can do that by overriding the admin css. You basically have to .vDateField, .vTimeField elements. Create a template admin/change_form.html in your templates folder. Add the following lines to that file

    {% extends "admin/change_form.html" %}
    {% block extrastyle %}
    .vDateField, .vTimeField {
        display: block;
    }
    {% endblock %}
    

    Django picks up this file, reads it and processes it before processing the original template file.