Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I display add model in tabular format in the Django admin?

Tags:

python

django

I'm just starting out with Django writing my first app - a chore chart manager for my family. In the tutorial it shows you how to add related objects in a tabular form. I don't care about the related objects, I just want to add the regular object in a tabular form. This is what I have in my admin.py

from chores.models import Chore
from django.contrib import admin

class ChoreAdmin(admin.ModelAdmin):
    fieldsets = [ 
        (None,              {'fields': ['description', 'frequency', 'person']})
    ]   

admin.site.register(Chore, ChoreAdmin)

and I want when I click "add chore" that rather than seeing:

Description: _____
Frequency: ______
Person: _____

I want it to show:

Description: __________ | Frequency: _______ | Person: _____

Is this trivial to do, or would it take a lot of custom effort? And if it is easy, how do I do it?

Thanks!

like image 976
Wayne Werner Avatar asked Jan 01 '11 18:01

Wayne Werner


2 Answers

OP is probably all set, but for new users reading this, refer to: https://docs.djangoproject.com/en/dev/ref/contrib/admin/

Basically following part in above link:


The field_options dictionary can have the following keys:

fields: A tuple of field names to display in this fieldset. This key is required.

Example:

{
'fields': ('first_name', 'last_name', 'address', 'city', 'state'),
}

Just like with the fields option, to display multiple fields on the same line, wrap those fields in their own tuple. In this example, the first_name and last_name fields will display on the same line:

{
'fields': (('first_name', 'last_name'), 'address', 'city', 'state'),
}
like image 142
Raj Avatar answered Oct 05 '22 07:10

Raj


Something to try,

class ChoreAdmin(admin.ModelAdmin):
 list_display = ('description', 'frequency', 'person')
 list_editable = ('description', 'frequency', 'person') 

Which should enable you to edit all your entries in a tabular form (if I've read the docs correctly)...

like image 40
aid Avatar answered Oct 05 '22 06:10

aid