How do you define a Django model?
Simple meaning
Subclass django.db.models.Model and declare fields such as CharField or ForeignKey.
Open the full page for Why, Steps, Example and Key takeaway.
Panel-ready Python & Django questions for freshers and experienced developers. Practice at Coding Cadre in Faridabad, or Online from Delhi NCR.
Subclass django.db.models.Model and declare fields such as CharField or ForeignKey.
Open the full page for Why, Steps, Example and Key takeaway.
A QuerySet is a lazy representation of a database query.
Open the full page for Why, Steps, Example and Key takeaway.
Call MyModel.objects.all() to get a QuerySet of every row.
Open the full page for Why, Steps, Example and Key takeaway.
ForeignKey stores a many-to-one relation: many child rows point at one parent.
Open the full page for Why, Steps, Example and Key takeaway.
Migrations are versioned Python files that describe schema changes.
Open the full page for Why, Steps, Example and Key takeaway.
pip is Python's standard package installer.
Open the full page for Why, Steps, Example and Key takeaway.
Run python -m pip install package-name so you invoke the pip that belongs to that interpreter.
Open the full page for Why, Steps, Example and Key takeaway.
requirements.txt lists packages and versions so a project can be reproduced.
Open the full page for Why, Steps, Example and Key takeaway.
python -m pip freeze prints installed distributions in requirements format.
Open the full page for Why, Steps, Example and Key takeaway.
A venv is an isolated directory with its own interpreter and site-packages.
Open the full page for Why, Steps, Example and Key takeaway.
Run python -m venv .venv (or another folder name) from the project root.
Open the full page for Why, Steps, Example and Key takeaway.
From PowerShell, run .venv\Scripts\Activate.ps1
Open the full page for Why, Steps, Example and Key takeaway.
Global installs mix unrelated projects and can break the system Python that OS tools rely on.
Open the full page for Why, Steps, Example and Key takeaway.
A decorator is a callable that takes a function and returns a new callable, usually wrapping extra behavior.
Open the full page for Why, Steps, Example and Key takeaway.
@my_dec above a function is the same as func = my_dec(func) after the def.
Open the full page for Why, Steps, Example and Key takeaway.
wraps copies the wrapped function's metadata such as __name__ and __doc__ onto the wrapper.
Open the full page for Why, Steps, Example and Key takeaway.
Open the full page for Why, Steps, Example and Key takeaway.
A generator is an iterator produced by a function that uses yield, or by a generator expression.
Open the full page for Why, Steps, Example and Key takeaway.
yield pauses the function and returns a value to the caller, preserving local state.
Open the full page for Why, Steps, Example and Key takeaway.
Use a for loop, which calls next() until StopIteration.
Open the full page for Why, Steps, Example and Key takeaway.