Creating and Saving Objects Live
Insert rows interactively to test ideas fast.
Creating and Saving Objects Live is a free Django Academy lesson on CoddyKit — lesson 3 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Django Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
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. 💾
Frequently asked questions
Is the “Creating and Saving Objects Live” lesson free?
Yes — the full text of “Creating and Saving Objects Live” is free to read here on the web, and the Django Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Django Academy course, upgrade to CoddyKit PRO.
What will I learn in “Creating and Saving Objects Live”?
Insert rows interactively to test ideas fast. You practise Django Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start Django Academy?
No prior experience is required. Django Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 3 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “Creating and Saving Objects Live” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this Django Academy lesson?
Yes. Every Django Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- Launching python manage.py shell
- Importing and Inspecting Models
- Creating and Saving Objects Live
- shell_plus and Better Tooling