Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change the layout and fields disposition of Django's Admin forms?

I have a simple model of a Student which is registered to the admin through a admin.ModelAdmin.

The admin change form of this model looks like this: Current look

I'd like to change the layout of this form a little so that a few fields could be in the same line, like so (edited in Paint): enter image description here

Is there something I could do without overriding the default templates? And if there isn't, what's the best way?

Thanks in advance.

like image 571
Eyal C Avatar asked Aug 31 '25 18:08

Eyal C


1 Answers

You can use fields attribute in ModelAdmin like this:

@admin.register(Student)
class StudentAdmin(admin.ModelAdmin):

    fields = (
        ('no_student', 'last_name', 'first_name),
        'course',
        'sex',
        'id'
    )

Fields grouped in one sub-tuple or sub-list will be shown in one line. You can create more than one groups like this.

like image 130
GwynBleidD Avatar answered Sep 02 '25 15:09

GwynBleidD