Releases: surenkov/django-pydantic-field
v0.2.5
What's Changed
- Add a bit of integration tests for models, forms and serializers by @surenkov in #17
- Properly override
get_prep_value
andget_db_prep_value
methods for PydanticSchemaField by @surenkov in #20
Important note:
This release fixes #19, thus Django < 4.2 users should avoid installing previous one, v0.2.4
.
I'm considering to delist 0.2.4 from PyPI to minimize the potential harm.
Full Changelog: v0.2.4...v0.2.5
v0.2.4
v0.2.3
v0.2.2
Properly declare supported Django versions
The package supports Django starting from 3.1.
Full Changelog: v0.2.0...v0.2.1
v0.2.0: Django 3.2 support
v0.1.13: Django form field support
v0.1.12: Union types support
Un additin to typed collections and pydantic types, the field now also supports typing.Union
, its special forms like typing.Optional
and (only for py 3.10+) X | Y
union annotations syntax.
What's Changed
Full Changelog: v0.1.11...v0.1.12
Enfoced null checks for `SchemaField`
Enforced null checks for SchemaField
In the example below, typing linters should enforce type compatibility:
class BuildingMeta(pydantic.BaseModel):
type: Optional[BuildingTypes]
class Building(models.Model):
opt_meta: BuildingMeta = SchemaField(default={"type": "frame"}, null=True)
meta: Optional[BuildingMeta] = SchemaField(default={"type": "frame"})
Pyright will complain on both fields:
sample_app/models.py:5:32 - error: Expression of type "BuildingMeta | None" cannot be assigned to declared type "BuildingMeta"
sample_app/models.py:6:40 - error: Expression of type "ST@SchemaField" cannot be assigned to declared type "BuildingMeta | None"
Mypy has more broaden resolution for latter check, but still be able to recognise first one:
sample_app/models.py:5: error: Incompatible types in assignment (expression has type "Optional[BuildingMeta]", variable has type "BuildingMeta")
Fixing field annotations will resolve issues on both checkers:
class Building(models.Model):
opt_meta: Optional[BuildingMeta] = SchemaField(default={"type": "frame"}, null=True)
meta: BuildingMeta = SchemaField(default={"type": "frame"})
The check also enforces default=None
to have null=True
param.
Relaxed restrictions on default=
argument
In addition to null enforcement, typing checks allow arbitrary values for default=
argument, as long as they are acceptable for pydantic's BaseModel.parse_obj
method. Callables are also accepted, mimicking Django's field semantics.
Full Changelog: v0.1.10...v0.1.11
v0.1.10
Slightly improve inheritance chain, better typings for SchemaField
factory function.
Full Changelog: v0.1.9...v0.1.10