lilott8
lilott8

Reputation: 1116

Altering the listview of the django admin portal

I've read, extensively, how to change the admin site of Django. I have it mostly figured out -- I think. However there are still a few things that elude me in my understanding. I am using the default registered admin urls; so they are not customized, only what is exposed automatically.

The easiest way to explain this is through imagery...

Here's what I have: original admin layout

Here's what I want: enter image description here

I'm fairly certain the changes should be fairly simple. But I don't know exactly which model to alter and template to adjust to get it to look how I want. The [number] -- [name] are fields in my model.

I have extended other pieces of the admin interface to get customized forms for editing particular elements -- by registering my model and customizing the field for it.

@admin.register(Course)
class CourseAdmin(admin.ModelAdmin):
    form = CourseAdminForm

    fieldsets = (
        ('Course Info:', {'fields': ('course_number', 'name', 'description', 'units')}),
        ('Load Info:', {'fields': ('lecture_hours', 'lab_hours', 'discussion_hours', 'work_hours')})
    )

in my app/admin.py file.

I'm a bit confused because there technically isn't a model to register here. So I'm not 100% sure how to do this. Do I wrap each one of my modifications inside the CourseAdmin class as different classes/methods with registered URLs or is there some other way I need to be doing this?

Upvotes: 0

Views: 529

Answers (1)

Gocht
Gocht

Reputation: 10256

You need edit your Course model class:

# models.py
class Course(models.Model):

    # fields here
    name = ...
    # ...

    # add a unicode method
    # __str__ method if you are using python 3.x
    def unicode(self):
        return '%s - %s' % (self.pk, self.name)

Upvotes: 1

Related Questions