python / beginner
Snippet
Basic QuerySet Filtering
QuerySets allow you to interact with the database using Python methods. The filter() method creates a subset of data that matches specific criteria.
snippet.py
1
2
3
4
from .models import Order# Retrieve only paid orderspaid_orders = Order.objects.filter(is_paid=True)
django
Breakdown
1
Order.objects
The 'objects' manager is the gateway for querying the Order model.
2
.filter(is_paid=True)
Applies a condition to the query, returning only records where the is_paid attribute is True.