Models & fields¶
dorm.Model¶
dorm.models.Model
¶
Base class for all ORM models.
save(using: str = 'default', force_insert: bool = False, force_update: bool = False, update_fields: list[str] | None = None) -> None
¶
asave(using: str = 'default', force_insert: bool = False, force_update: bool = False, update_fields: list[str] | None = None) -> None
async
¶
delete(using: str = 'default') -> tuple[int, dict[str, int]]
¶
adelete(using: str = 'default') -> tuple[int, dict[str, int]]
async
¶
refresh_from_db(using: str = 'default', fields=None)
¶
Re-fetch this row from the database, optionally restricting to a subset of columns.
When fields= is given, the SELECT is narrowed to those
columns via :meth:QuerySet.only so the database transfers
only what's actually being refreshed — important on tables
with large TEXT/BLOB/JSON columns where the previous
SELECT * paid a real bandwidth cost. Unknown field names
are silently skipped (matches the long-standing behaviour
callers depend on for partial refreshes after a
__set_changed hook).
arefresh_from_db(using: str = 'default', fields=None)
async
¶
Async counterpart of :meth:refresh_from_db. Same
fields= narrowing applies.
full_clean(exclude: list[str] | None = None) -> None
¶
Field types¶
dorm.fields.Field
¶
Bases: Generic[_T]
Base class for all dorm fields.
The generic parameter _T is the Python type the field stores. Static
type checkers use it via the overloaded __get__ so user.name
(where name = CharField(...)) is inferred as str, not Any.
Runtime behaviour is identical regardless of the parameter.
deconstruct() -> tuple[str | None, str, list, dict]
¶
Return a 4-tuple suitable for migration serialisation:
(name, dotted_class_path, args, kwargs).
Mirrors Django's :meth:django.db.models.Field.deconstruct
so custom fields the user writes — and migration tools that
consume them — can reconstruct a Field instance from
the serialised form by:
.. code-block:: python
from importlib import import_module
mod_path, _, cls_name = path.rpartition(".")
cls = getattr(import_module(mod_path), cls_name)
field = cls(*args, **kwargs)
The default implementation walks the constructor's keyword
arguments and emits whichever ones differ from the
framework-shipped defaults. Subclasses with extra
constructor parameters should override and call super()
first to extend the kwargs dict.
dorm.fields.BigIntegerField
¶
Bases: IntegerField
dorm.fields.SmallIntegerField
¶
Bases: IntegerField
dorm.fields.PositiveIntegerField
¶
Bases: IntegerField
dorm.fields.PositiveSmallIntegerField
¶
Bases: PositiveIntegerField
dorm.fields.DateTimeField
¶
Bases: Field[datetime]
Datetime column.
settings.USE_TZ controls timezone handling:
False(default, Django <4 behaviour): naive datetimes are stored as-is. Aware datetimes are stored verbatim.True(Django ≥4 behaviour): every read returns a tz-aware datetime. Naive datetimes coming in from the user are interpreted insettings.TIME_ZONEand converted to UTC before storage. PostgreSQL columns becomeTIMESTAMP WITH TIME ZONEso the engine round-trips the offset.
dorm.fields.ArrayField
¶
Bases: Field[list]
PostgreSQL native array column.
Stores a homogeneous list of values whose element type is given by
base_field. SQLite doesn't have arrays — this field raises
NotImplementedError at db_type time on SQLite so you find
out at migrate, not at query.
Example::
class Article(dorm.Model):
tags = dorm.ArrayField(dorm.CharField(max_length=50), null=True)
Usage::
Article.objects.create(tags=["python", "orm"])
# Filter for membership (PG ``ANY`` operator) — use ``__contains``:
Article.objects.filter(tags__contains=["python"])
dorm.fields.ForeignKey
¶
Bases: RelatedField
dorm.fields.OneToOneField
¶
Bases: RelatedField