What is a Django foreign key?
It links a row to another model, such as a task to its owner. Choose on_delete based on what should happen when the referenced row disappears.
What is a Django many-to-many relationship?
It connects multiple records on each side. For example, a course can have multiple tags and a tag can describe multiple courses.
When should I use select_related in Django?
Use it for single-valued relationships when you will read related data for many results. It retrieves the related rows in the same query using joins.
When should I use prefetch_related in Django?
Use it when you need related collections, such as tags for each article. Django fetches related records separately and links them to the results.
Why does a Django list page run too many database queries?
Reading related fields separately for each row can create an N+1 pattern. Inspect query counts and load the needed relationships in batches.
How do I require login for a Django view?
Use login_required for a function view or LoginRequiredMixin for an appropriate class-based view. Add separate checks for access to private records.
What is the POST-redirect-GET pattern?
After processing a successful POST, redirect to a GET page. Refreshing the result then repeats the GET without resubmitting the original form.
What is a Django fixture?
It is a serialized collection of data that Django can load, for example a set of demo categories. Keep private production data out of shared fixtures.
Explore related topics in the ScholarLogic project Q&A guide.