0Pricing
Django Academy · Lektion

ModelAdmin anpassen

Legen Sie list_display, list_filter und search_fields fest.

ModelAdmin anpassen ist eine kostenlose Django Academy-Lektion auf CoddyKit. Dies ist Lektion 3 von 4. Du kannst die komplette Lektion unten kostenlos lesen – dann übst du sie direkt im Browser mit einem integrierten Code-Editor und einem KI-Tutor rund um die Uhr. Sie ist Teil des Django Academy-Lernpfads, und dein Fortschritt wird über Web und CoddyKit-App synchronisiert. Der Django Academy-Kurs umfasst insgesamt 4 Lektionen.

Teile dieser Lektion wurden noch nicht übersetzt und werden auf Englisch angezeigt.

Beyond the Defaults

The default admin works but feels plain. A ModelAdmin class lets you reshape how each model looks and behaves in the admin.

Subclass and Attach

Create a class that subclasses admin.ModelAdmin, then pass it when you register the model. That class holds all your tweaks.

class PostAdmin(admin.ModelAdmin):
    pass
admin.site.register(Post, PostAdmin)

Columns in the List

The list page shows one column by default. Set list_display to a tuple of field names and the admin renders each as a column.

list_display = ("title", "author", "created")

Filter the Sidebar

Big tables get hard to scan. Add list_filter and the admin shows a sidebar to narrow rows by those fields fast. 🔍

list_filter = ("status", "created")

Add a Search Box

Let staff hunt for records by text. Setting search_fields puts a search bar at the top that scans those fields.

search_fields = ("title", "author__name")

Click to Edit

By default only the first column links to the edit page. Use list_display_links to choose which columns are clickable instead.

list_display_links = ("title",)

Edit Inline in the List

Want to change a value without opening each row? Put a field in list_editable and you can edit it right on the list page.

list_editable = ("status",)

Prefill the Slug

Slugs are tedious to type. The prepopulated_fields option fills a slug live from the title as you type it. ⚡

prepopulated_fields = {"slug": ("title",)}

Order the Rows

Control the default sort with ordering. A leading minus sorts that field descending, so newest items can lead the list.

ordering = ("-created",)

Group the Form

Long edit forms feel cluttered. Use fieldsets to split fields into labeled, collapsible sections on the edit page.

Computed Columns

list_display can also call a method on your admin class. That lets you show derived values, like a short preview of the body.

def short(self, obj):
    return obj.body[:30]

Quick Check

Which option controls the columns shown on the list page?

Recap

With ModelAdmin you added columns, filters, search, and sorting. A few attributes turn a plain table into a powerful data console. 🛠️

Häufig gestellte Fragen

Ist die Lektion „ModelAdmin anpassen“ kostenlos?

Ja — der vollständige Text von „ModelAdmin anpassen“ ist hier im Web kostenlos zu lesen. Um sie interaktiv zu üben (integrierter Code-Editor und 24/7 KI-Tutor) und den Rest des Django Academy-Kurses freizuschalten, upgrade auf CoddyKit PRO. Der Django Academy-Kurs umfasst insgesamt 4 Lektionen.

Was lerne ich in „ModelAdmin anpassen“?

Legen Sie list_display, list_filter und search_fields fest. Du übst Django Academy mit praktischem Code, den du direkt im Browser ausführst, und ein 24/7 KI-Tutor beantwortet deine Fragen während du die Lektion bearbeitest.

Brauche ich Erfahrung, um Django Academy zu starten?

Keine Vorkenntnisse erforderlich. Django Academy auf CoddyKit ist für Anfänger bis fortgeschrittene Lernende strukturiert, sodass du hier starten oder von Anfang an beginnen und in deinem eigenen Tempo voranschreiten kannst. Dies ist Lektion 3 von 4.

Wie lange dauert die Lektion „ModelAdmin anpassen“?

Die meisten CoddyKit-Lektionen dauern etwa 5–10 Minuten. Jede ist kompakt und interaktiv, sodass du stetig Fortschritte machst und genau dort weitermachst, wo du aufgehört hast – im Web und in der App.

Kann ich in dieser Django Academy-Lektion Code schreiben und ausführen?

Ja. Jede Django Academy-Lektion enthält einen integrierten Code-Editor, sodass du echten Code direkt in deinem Browser schreibst und ausführst und sofort KI-Feedback erhältst — ohne lokale Einrichtung erforderlich.

Alle Lektionen in diesem Kurs

  1. createsuperuser und anmelden
  2. Models mit admin.site registrieren
  3. ModelAdmin anpassen
  4. Inlines und schreibgeschützte Felder
← Zurück zu Django Academy