Skip to content

Retrieve a single record

To retrieve a single record from a table in the database, you can use the get() method on the model manager.

from myapp.models import MyModel
# Retrieve a single record from the MyModel table
record = MyModel.objects.get(id=1)

This will return a single record from the MyModel table with the id field equal to 1. If no record is found with the specified criteria, a DoesNotExist exception will be raised. You can catch this exception and handle it as needed.