Crear y guardar objetos en tiempo real
Inserte filas de forma interactiva para probar ideas rápidamente
Crear y guardar objetos en tiempo real es una lección gratuita de Django Academy en CoddyKit. Esta es la lección 3 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.
Make a Row from Scratch
The shell lets you create database rows by hand. Start by building an instance with the values you want.
>>> p = Post(title="Hello", body="My first post")Nothing Saved Yet
That instance lives only in memory so far. The database knows nothing about it until you explicitly write it.
Save to Persist
Call save() to insert the row. Django runs the SQL and your object now lives in the database for real.
>>> p.save()Django Assigns an ID
After saving, your object gets a primary key in p.pk. A value means the insert succeeded and the row exists.
>>> p.pk
1The One-Step Shortcut
Prefer fewer steps? create() builds and saves in a single call, returning the finished object right away.
>>> Post.objects.create(title="Two", body="Quick")Edit Then Save Again
To update, change an attribute and call save() once more. Django writes only the new values to that row.
>>> p.title = "Edited"
>>> p.save()Read It Back
Confirm the write by fetching the row with get(). Seeing it returned proves your data really landed.
>>> Post.objects.get(pk=1)Count Your Rows
A fast sanity check is count(). It tells you how many rows the table holds after your inserts.
>>> Post.objects.count()
2Delete When Needed
Clean up test data with delete() on an instance. The row is removed from the database immediately.
>>> p.delete()It Writes to the Real DB
Remember these changes are permanent. The shell talks to your actual database, so avoid experimenting on production data.
Great for Seeding Test Data
This live flow is perfect for seeding a few rows while you build features, so pages have something to display.
Quick Check
Which call builds and saves a row in one step?
Recap
You created objects, used save() and create() to persist them, then read, counted, and deleted rows live in the shell. 💾
Preguntas frecuentes
¿La lección «Crear y guardar objetos en tiempo real» es gratis?
Sí — el texto completo de «Crear y guardar objetos en tiempo real» 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 «Crear y guardar objetos en tiempo real»?
Inserte filas de forma interactiva para probar ideas rápidamente 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 3 de 4.
¿Cuánto tiempo toma la lección «Crear y guardar objetos en tiempo real»?
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
- Iniciar python manage.py shell
- Importar e inspeccionar modelos
- Crear y guardar objetos en tiempo real
- shell_plus y mejores herramientas