Reputation: 1709
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:
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):
Is there something I could do without overriding the default templates? And if there isn't, what's the best way?
Thanks in advance.
Upvotes: 4
Views: 2432
Reputation: 20569
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.
Upvotes: 8
Reputation: 1461
You can do this by using fieldsets.
class StudentAdmin(admin.ModelAdmin):
fieldsets = (
(None, {
'fields': (('no_student', 'last_name', 'first_name), 'course', 'sex', 'ID')
}),
...
)
Please note i have wrapped the fields which should be shown in single line in same tuple.
Upvotes: 2