Skip to content

Saving an Animal

Our database has a table for animals now, so we can save one. We'll do it in the Django shell, a Python REPL with our project loaded.

Start the shell:

shell
uv run manage.py shell
Python REPL
>>> from datetime import date
>>> rocket = Animal.objects.create(name="Rocket", species="dog", birth_date=date(2023, 4, 12))
>>> rocket
<Animal: Rocket>
>>> rocket.intake_date
datetime.date(2026, 10, 17)

Queries to Animal start with Animal.objects. create() builds an Animal and saves it as a new row in one step.

The shell shows the new animal with our __str__, and intake_date has today's date from its default.

Info

manage.py shell imports the models from every installed app, so Animal is available without an import. Other names, such as date, still need to be imported.