0Pricing
Django Academy · Lección

Registrar modelos con admin.site

Haga que sus modelos puedan editarse en el administrador

Registrar modelos con admin.site es una lección gratuita de Django Academy en CoddyKit. Esta es la lección 2 de 4. Puedes leer la lección completa abajo gratuitamente — luego la practicas en el navegador con un editor de código integrado y un tutor de IA 24/7. Forma parte de la ruta de aprendizaje de Django Academy, y tu progreso se sincroniza en la web y la app de CoddyKit. El curso de Django Academy incluye 4 lecciones en total.

Partes de esta lección aún no han sido traducidas y se muestran en inglés.

Empty Dashboard

Right now the admin only shows Users and Groups. To manage your own data you must register each model so the admin knows about it.

Where to Register

Each app has its own admin.py file. This is the one place you tell Django which models should appear in the admin.

Import the Tool

First bring in the admin module. The admin object is your gateway to registering models and customizing the site.

from django.contrib import admin

Import Your Model

Next import the model you want to manage. Pull it in from your app's models module so admin.py can reference it.

from .models import Post

Register It

Now hand the model to the admin. Calling admin.site.register() adds that model straight onto the dashboard.

admin.site.register(Post)

See It Appear

Refresh /admin and your model is now listed with built-in add, edit, and delete screens. No extra views needed. ✨

Register Many

Got several models? Just import each one and call register again. Every register call gives that model its own admin section.

admin.site.register(Author)
admin.site.register(Tag)

The Decorator Way

There is a cleaner style too. The @admin.register decorator registers a model right above its admin class in one step.

@admin.register(Post)
class PostAdmin(admin.ModelAdmin):
    pass

Friendly Names

The admin shows each row using the model's __str__ method. A good __str__ turns cryptic rows into readable labels.

def __str__(self):
    return self.title

Already Registered

Register the same model twice and Django raises AlreadyRegistered. Each model belongs to exactly one register call.

Restart Not Needed

The dev server auto-reloads when you save admin.py, so just refresh the page. Your newly registered model shows up instantly.

Quick Check

How do you make a model appear in the admin?

Recap

In admin.py you imported a model and registered it, and it appeared on the dashboard with full CRUD screens. That is the core admin workflow. 🎉

Preguntas frecuentes

¿La lección «Registrar modelos con admin.site» es gratis?

Sí — el texto completo de «Registrar modelos con admin.site» es gratis para leer aquí en la web. Para practicarla de forma interactiva (editor de código integrado y tutor de IA 24/7) y desbloquear el resto del curso de Django Academy, actualiza a CoddyKit PRO. El curso de Django Academy incluye 4 lecciones en total.

¿Qué aprenderé en «Registrar modelos con admin.site»?

Haga que sus modelos puedan editarse en el administrador Practicas Django Academy con código real que ejecutas directamente en el navegador, y un tutor de IA 24/7 responde tus preguntas mientras trabajas en la lección.

¿Necesito experiencia previa para empezar Django Academy?

No se requiere experiencia previa. Django Academy en CoddyKit está estructurado para principiantes hasta estudiantes avanzados, así que puedes empezar aquí o desde el inicio y avanzar a tu ritmo. Esta es la lección 2 de 4.

¿Cuánto tiempo toma la lección «Registrar modelos con admin.site»?

La mayoría de las lecciones de CoddyKit toman alrededor de 5–10 minutos. Cada una es compacta e interactiva, así que avanzas constantemente y retomas exactamente por donde dejaste en la web y la app.

¿Puedo escribir y ejecutar código en esta lección de Django Academy?

Sí. Cada lección de Django Academy incluye un editor de código integrado, así que escribes y ejecutas código real directamente en tu navegador y obtienes retroalimentación instantánea de IA — sin configuración local necesaria.

Todas las lecciones de este curso

  1. createsuperuser e inicio de sesión
  2. Registrar modelos con admin.site
  3. Personalizar ModelAdmin
  4. Inlines y campos de solo lectura
← Volver a Django Academy