NewYour coding agent can read the release notes before it upgrades.Set up the MCP server →
PyPI · #2675 most downloaded on PyPI
Type-Safe Pydantic Schemas for Django JSONFields
Last release 7 months ago
22 Feb 2026
Release timing varies
gaps range from 2 weeks to 6 months
Most releases are documented
notes for 48 of 58 stable releases
4 versions withdrawn
withdrawn after publishing
4 years old
69 releases · first in 2022
One column per quarter.
Fix migration mypy error. by @noamkush in #104
Refactored forward reference evaluation using typing-extensions to suppress DeprecationWarning regarding missing type_params .
Bug Fixes
UserWarning triggered by Pydantic v1 in Python 3.14.typing-extensions to suppress DeprecationWarning regarding missing type_params.Maintenance
ty version.type: ignore comments.Full Changelog: v0.5.2...v0.5.3
Migration Serialization: Fixed an infinite recursion issue when serializing union types (e.g., list[Model] | None ) in Django migrations on Python 3.1
Bug Fixes
list[Model] | None) in Django migrations on Python 3.11+. The fix wraps union arguments in a container to prevent Django’s IterableSerializer from recursing infinitely, ensuring migrations for complex schema fields are generated correctly.Improvements
SchemaField to better support nullable schemas (e.g., SchemaField(schema=MyModel | None, null=True)). This improves static analysis compatibility when defining nullable fields and their default values.Full Changelog: v0.5.1...v0.5.2
Declare support for TypedDict protocols as valid schemas in SchemaField.
TypedDict protocols as valid schemas in SchemaField.conint, constr) and Annotated types using annotated_types or StringConstraints in Django migrations.RepresentationSerializer now correctly returns required imports.dataclass instances nested within generic containers (like list or dict) were not correctly wrapped for serialization.Full Changelog: https://github.com/surenkov/django-pydantic-field/compare/v0.5.0...v0.5.1
TypedDict protocols as valid schemas in SchemaField.conint, constr) and Annotated types using annotated_types or StringConstraints in Django migrations.RepresentationSerializer now correctly returns required imports.dataclass instances nested within generic containers (like list or dict) were not correctly wrapped for serialization.Full Changelog: v0.5.0...v0.5.1
The core adaptation logic is moved into a SchemaAdapter layer that handles both Pydantic v1 and v2 through the same interface.
The core adaptation logic is moved into a SchemaAdapter layer that handles both Pydantic v1 and v2 through the same interface.
SchemaAdapter, we’ve eliminated a lot of “if Pydantic v2 do this, else do that” code. This makes the field behavior identical regardless of which Pydantic version you are running..v1 subpackage.
If you are running Pydantic v2 but still need to use legacy Pydantic v1 models, you can now do so explicitly by importing the field from the .v1 subpackage:from django_pydantic_field.v1 import SchemaField as SchemaFieldV1
uv for dependency management and building. This won’t affect library users, but it makes contributing easier.AutoSchema provided in django_pydantic_field.rest_framework.src/ layout. This shouldn’t affect standard installations, but if you were importing from internal file paths or using a non-standard setup, you may need to adjust your configuration.Full Changelog: https://github.com/surenkov/django-pydantic-field/compare/v0.4.1...v0.5.0
Pydantic v2 types like conint and StringConstraints use internal objects (e.g., annotated_types.Gt) that Django cannot serialize by default. By ensuri
(backport of 0.5.1 fix)
Pydantic v2 types like conint and StringConstraints use internal objects (e.g., annotated_types.Gt) that Django cannot serialize by default. By ensuring GenericContainer wraps these dataclass-like instances and fixing the RepresentationSerializer to return necessary imports, these types can now be used in Django migrations.
Addresses https://github.com/surenkov/django-pydantic-field/issues/72, but only for Pydantic v2. Pydantic v1 requires a different approach as it generates the ad-hoc constrained types, and in light of https://github.com/surenkov/django-pydantic-field/issues/35 and https://github.com/surenkov/django-pydantic-field/issues/71, not worth an effort.
Full Changelog: https://github.com/surenkov/django-pydantic-field/compare/v0.4.1...v0.4.2
(backport of 0.5.1 fix)
Pydantic v2 types like conint and StringConstraints use internal objects (e.g., annotated_types.Gt) that Django cannot serialize by default. By ensuring GenericContainer wraps these dataclass-like instances and fixing the RepresentationSerializer to return necessary imports, these types can now be used in Django migrations.
Addresses #72, but only for Pydantic v2. Pydantic v1 requires a different approach as it generates the ad-hoc constrained types, and in light of #35 and #71, not worth an effort.
Full Changelog: v0.4.1...v0.4.2
Add support for Django 6.0 by @RealOrangeOne in https://github.com/surenkov/django-pydantic-field/pull/88
Full Changelog: https://github.com/surenkov/django-pydantic-field/compare/v0.4.0...v0.4.1
Full Changelog: v0.4.0...v0.4.1
Fixes for Python 3.14. by @noamkush in https://github.com/surenkov/django-pydantic-field/pull/85
Full Changelog: https://github.com/surenkov/django-pydantic-field/compare/v0.3.13...v0.4.0
Full Changelog: v0.3.13...v0.4.0
Pydantic v2 types like conint and StringConstraints use internal objects (e.g., annotated_types.Gt) that Django cannot serialize by default. By ensuri
(backport of 0.5.1 fix)
Pydantic v2 types like conint and StringConstraints use internal objects (e.g., annotated_types.Gt) that Django cannot serialize by default. By ensuring GenericContainer wraps these dataclass-like instances and fixing the RepresentationSerializer to return necessary imports, these types can now be used in Django migrations.
Addresses https://github.com/surenkov/django-pydantic-field/issues/72, but only for Pydantic v2. Pydantic v1 requires a different approach as it generates the ad-hoc constrained types, and in light of https://github.com/surenkov/django-pydantic-field/issues/35 and https://github.com/surenkov/django-pydantic-field/issues/71, not worth an effort.
Full Changelog: https://github.com/surenkov/django-pydantic-field/compare/v0.3.13...v0.3.14
(backport of 0.5.1 fix)
Pydantic v2 types like conint and StringConstraints use internal objects (e.g., annotated_types.Gt) that Django cannot serialize by default. By ensuring GenericContainer wraps these dataclass-like instances and fixing the RepresentationSerializer to return necessary imports, these types can now be used in Django migrations.
Addresses #72, but only for Pydantic v2. Pydantic v1 requires a different approach as it generates the ad-hoc constrained types, and in light of #35 and #71, not worth an effort.
Full Changelog: v0.3.13...v0.3.14
feat: fallback on json parsing in case of error by @quertenmont in #83
Full Changelog: v0.3.12...v0.3.13
Drop Python 3.7, declare 3.13 support by @surenkov in https://github.com/surenkov/django-pydantic-field/pull/76
django.core.exceptions.ValidationError by @surenkov in https://github.com/surenkov/django-pydantic-field/pull/79from_db_value by @surenkov in https://github.com/surenkov/django-pydantic-field/pull/78Full Changelog: https://github.com/surenkov/django-pydantic-field/compare/v0.3.11...v0.3.12
fix ValidationError on empty form rendering by @amyasnikov in https://github.com/surenkov/django-pydantic-field/pull/75
Full Changelog: https://github.com/surenkov/django-pydantic-field/compare/v0.3.10...v0.3.11
Propagate allow_null parameter to base DRF Field by @surenkov in https://github.com/surenkov/django-pydantic-field/pull/70
allow_null parameter to base DRF Field by @surenkov in https://github.com/surenkov/django-pydantic-field/pull/70Full Changelog: https://github.com/surenkov/django-pydantic-field/compare/v0.3.9...v0.3.10
Bypass field validation on model instantiation if it does not contain a default= argument by @surenkov in https://github.com/surenkov/django-pydantic-
default= argument by @surenkov in https://github.com/surenkov/django-pydantic-field/pull/63Full Changelog: https://github.com/surenkov/django-pydantic-field/compare/v0.3.8...v0.3.9
Add django-jsonform widget incorporation for v2 fields by @surenkov in https://github.com/surenkov/django-pydantic-field/pull/59
django-jsonform widget incorporation for v2 fields by @surenkov in https://github.com/surenkov/django-pydantic-field/pull/59Full Changelog: https://github.com/surenkov/django-pydantic-field/compare/v0.3.7...v0.3.8
In 0.3.5, I introduced an incompatibility with Pydantic v1: particularly, importing pydantic_core unconditionally in compatibility layer . Thank you @
In 0.3.5, I introduced an incompatibility with Pydantic v1: particularly, importing pydantic_core unconditionally in compatibility layer :eyes:. Thank you @Abdullah0297445 for the bringing attention to this!
Both 0.3.5 and 0.3.6 were yanked from PyPI, I highly encourage to upgrade your pinned versions if you're the lucky one who has experienced this issue.
Full Changelog: https://github.com/surenkov/django-pydantic-field/compare/v0.3.6...v0.3.7
Use mode=json for get_prep_value during field value serialization by @surenkov in https://github.com/surenkov/django-pydantic-field/pull/57
mode=json for get_prep_value during field value serialization by @surenkov in https://github.com/surenkov/django-pydantic-field/pull/57Full Changelog: https://github.com/surenkov/django-pydantic-field/compare/v0.3.5...v0.3.6
Setup pre-commit by @surenkov in https://github.com/surenkov/django-pydantic-field/pull/53
pre-commit by @surenkov in https://github.com/surenkov/django-pydantic-field/pull/53typing.Annotated annotations by @surenkov in https://github.com/surenkov/django-pydantic-field/pull/52Full Changelog: https://github.com/surenkov/django-pydantic-field/compare/v0.3.4...v0.3.5
Prepare a SchemaField's default value to work with RootModel schemas by @surenkov in https://github.com/surenkov/django-pydantic-field/pull/51
default value to work with RootModel schemas by @surenkov in https://github.com/surenkov/django-pydantic-field/pull/51Full Changelog: https://github.com/surenkov/django-pydantic-field/compare/v0.3.3...v0.3.4
Allow (deprecated) django_pydantic_field.rest_framework.AutoSchema import with Pydantic 2.
Make sure all expected primitives are exposed during dynamic module resolution in compatibility layer.
Allow (deprecated) django_pydantic_field.rest_framework.AutoSchema import with Pydantic 2.
Full Changelog: https://github.com/surenkov/django-pydantic-field/compare/v0.3.2...v0.3.3
forms.SchemaField.to_python(): check if value already has a target type by @alexey-sveshnikov in https://github.com/surenkov/django-pydantic-field/pul
Full Changelog: https://github.com/surenkov/django-pydantic-field/compare/v0.3.1...v0.3.2
Full Changelog: https://github.com/surenkov/django-pydantic-field/compare/v0.3.1...v0.3.2b1
Full Changelog: https://github.com/surenkov/django-pydantic-field/compare/v0.3.1...v0.3.2b1
Add expressions handling for get_prep_value in v1 by @surenkov in https://github.com/surenkov/django-pydantic-field/pull/47
get_prep_value in v1 by @surenkov in https://github.com/surenkov/django-pydantic-field/pull/47Full Changelog: https://github.com/surenkov/django-pydantic-field/compare/v0.3.0...v0.3.1
This release centers on the incorporation of v2 primitives. In the earlier version, Pydantic v1, support was achieved through a series of workarounds
This release centers on the incorporation of v2 primitives. In the earlier version, Pydantic v1, support was achieved through a series of workarounds involving the manipulation of passed (or annotated) schemas. These schemas were wrapped into an intermediary RootModel to support both Pydantic models and most of the arbitrary annotations.
With v2, pydantic now ships a new primitive -- TypeAdapter -- which is well designed for this particular machinery.
To support both Pydantic v1 and v2, which might be useful during migration step, I added an indirection level during the import step.
0.3.0 contains implementations for both versions, with changes in v1 only required to make this compatibility layer to operate, with all behaviour remaining as in 0.2.13.
In 0.2.* versions, exact schema resolution had been done in three stages:
contribute_to_class method.In this update, I decided that evaluation logic should be as simple as possible, thus keeping only stage 3, and removing all the dirty logic that supported the machinery around 1 and 2 stages. To mitigate possible schema evaluation errors, which may appear only in runtime, the field now performs a few checks that are being performed by Django during app development lifecycle:
manage.py checkmanage.py runservermanage.py makemigrationsmanage.py migrateThis check is relied on the same mechanics that you might see in plain JSONField, complaining on passing mutable structures itself, instead of callables (Django's field.E010 warning).
Along with the schema evaluation check, the field now performes a few others, to make sure of its integrity:
pydantic.E001 (a check from the section above). The schema cannot be resolved. It is most likely a programmatic error -- forward references cannot be resolved in the Django model's execution context.pydantic.E002. The field's default= value cannot be serialized by the specified schema. This may lead to runtime errors during model .save() or .objects.create(...) methods.pydantic.E003. If the field contains include= or exclude= export arguments, there could be a situation that value, written in the database, could not be restored back to python from its serialized form. This check tries to pass the specified default value (or the one that could be inferred directly from the schema, if default= is missing), through the whole transformation cycle, yielding a warning if the value could not be transformed back to python.Additionally, JSONField's field.E010 warning is suppressed, as it is meaningless due to the nature of field transformations -- we're always getting a new value, not reusing the one passed to default= argument.
Full Changelog: https://github.com/surenkov/django-pydantic-field/compare/v0.2.14...v0.3.0
Django serialization support by @amyasnikov in https://github.com/surenkov/django-pydantic-field/pull/41
Full Changelog: https://github.com/surenkov/django-pydantic-field/compare/v0.3.0b1...v0.3.0b2
Full Changelog: https://github.com/surenkov/django-pydantic-field/compare/v0.3.0a5...v0.3.0b1
Full Changelog: https://github.com/surenkov/django-pydantic-field/compare/v0.3.0a5...v0.3.0b1
Add py.typed marker by @surenkov in https://github.com/surenkov/django-pydantic-field/pull/40
py.typed marker by @surenkov in https://github.com/surenkov/django-pydantic-field/pull/40Full Changelog: https://github.com/surenkov/django-pydantic-field/compare/v0.3.0a4...v0.3.0a5
Update README.md in https://github.com/surenkov/django-pydantic-field/pull/38;
Full Changelog: https://github.com/surenkov/django-pydantic-field/compare/v0.3.0a3...v0.3.0a4
Declare Django 5.0 support by @surenkov in https://github.com/surenkov/django-pydantic-field/pull/37
Full Changelog: https://github.com/surenkov/django-pydantic-field/compare/v0.3.0a2...v0.3.0a3
Previous pre-release contained a broken package. Here's the new one (:
Previous pre-release contained a broken package. Here's the new one (:
Full Changelog: https://github.com/surenkov/django-pydantic-field/compare/v0.3.0a1...v0.3.0a2
This release is specifically focused on adding v2 primitives. Pydantic v1 was supported by a trickery around passed (or annotated) schema, wrapping it
0.3.0a1 contained a broken package. Please take a look on 0.3.0a2 if you like to test it in the wild (:This release is specifically focused on adding v2 primitives. Pydantic v1 was supported by a trickery around passed (or annotated) schema, wrapping it into intermediary RootModel to support both pydantic models and most of arbitrary annotations.
With v2, pydantic now contains the primitive -- TypeAdapter -- which is well designed for this particular machinery.
There's one remaining primitive is to be migrated prior final 0.3.0 -- OpenAPI AutoSchema generator, but since this library is already not super-sticky to the OpenAPI standard, I decided that alpha release could be rolled out without it.
To support both Pydantic v1 and v2, which might be useful during migration step, I added an indirection level during the import step.
0.3.0 contains implementations for both versions, with changes in v1 only required to make this compatibility layer to operate, with all behaviour remaining as in 0.2.11.
In 0.2.* versions, exact schema resolution had been done in three stages:
contribute_to_class method.In this update, I decided that evaluation logic should be as simple as possible, thus keeping only stage 3, and removing all the dirty logic that supported the machinery around 1 and 2 stages. To mitigate possible schema evaluation errors, which may appear only in runtime, the field now performs a few checks that are being performed by Django during app development lifecycle:
manage.py checkmanage.py runservermanage.py makemigrationsmanage.py migrateThis check is relied on the same mechanics that you might see in plain JSONField, complaining on passing mutable structures itself, instead of callables (Django's field.E010 warning).
Along with the schema evaluation check, the field now performes a few others, to make sure of its integrity:
pydantic.E001 (a check from the section above). The schema cannot be resolved. It is most likely a programmatic error -- forward references cannot be resolved in the Django model's execution context.pydantic.E002. The field's default= value cannot be serialized by the specified schema. This may lead to runtime errors during model .save() or .objects.create(...) methods.pydantic.E003. If the field contains include= or exclude= export arguments, there could be a situation that value, written in the database, could not be restored back to python from its serialized form. This check tries to pass the specified default value (or the one that could be inferred directly from the schema, if default= is missing), through the whole transformation cycle, yielding a warning if the value could not be transformed back to python.Additionally, JSONField's field.E010 warning is suppressed, as it is meaningless due to the nature of field transformations -- we're always getting a new value, not reusing the one passed to default= argument.
Full Changelog: https://github.com/surenkov/django-pydantic-field/compare/v0.2.11...v0.3.0a1
Backport django.core.serializers support by @surenkov in https://github.com/surenkov/django-pydantic-field/pull/42
Full Changelog: https://github.com/surenkov/django-pydantic-field/compare/v0.2.13...v0.2.14
Add py.typed marker by @surenkov in https://github.com/surenkov/django-pydantic-field/pull/40
py.typed marker by @surenkov in https://github.com/surenkov/django-pydantic-field/pull/40Full Changelog: https://github.com/surenkov/django-pydantic-field/compare/v0.2.12...v0.2.13
Declare Django 5.0 support by @surenkov in https://github.com/surenkov/django-pydantic-field/pull/37
Full Changelog: https://github.com/surenkov/django-pydantic-field/compare/v0.2.11...v0.2.12
Preserve kwargs for json.dumps() by @fdemmer in https://github.com/surenkov/django-pydantic-field/pull/30
Full Changelog: https://github.com/surenkov/django-pydantic-field/compare/v0.2.10...v0.2.11
Raise ValidationError on form invalid JSON payload by @surenkov in https://github.com/surenkov/django-pydantic-field/pull/29
Full Changelog: https://github.com/surenkov/django-pydantic-field/compare/v0.2.9...v0.2.10
Ensure that attributes set during contribute_to_class are copied. by @TomTruck in https://github.com/surenkov/django-pydantic-field/pull/27
contribute_to_class are copied. by @TomTruck in https://github.com/surenkov/django-pydantic-field/pull/27Full Changelog: https://github.com/surenkov/django-pydantic-field/compare/v0.2.8...v0.2.9
Add backward support for pydantic 1.9.* by @surenkov in https://github.com/surenkov/django-pydantic-field/pull/26
Full Changelog: https://github.com/surenkov/django-pydantic-field/compare/v0.2.7...v0.2.8
Updates to deconstruct() in SchemaField to preserve values of include and exclude by @oomojola in https://github.com/surenkov/django-pydantic-field/pu
Full Changelog: https://github.com/surenkov/django-pydantic-field/compare/v0.2.6...v0.2.7
Bring back JSON field lookups to work with schema [Django 4.2] by @surenkov in https://github.com/surenkov/django-pydantic-field/pull/22
Full Changelog: https://github.com/surenkov/django-pydantic-field/compare/v0.2.5...v0.2.6
Add a bit of integration tests for models, forms and serializers by @surenkov in https://github.com/surenkov/django-pydantic-field/pull/17
get_prep_value and get_db_prep_value methods for PydanticSchemaField by @surenkov in https://github.com/surenkov/django-pydantic-field/pull/20This 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: https://github.com/surenkov/django-pydantic-field/compare/v0.2.4...v0.2.5
Add support for Django 4.2 by @surenkov in https://github.com/surenkov/django-pydantic-field/pull/15
Full Changelog: https://github.com/surenkov/django-pydantic-field/compare/v0.2.3...v0.2.4
Migrate setup.cfg to the sole pyproject.toml by @surenkov in https://github.com/surenkov/django-pydantic-field/pull/13
setup.cfg to the sole pyproject.toml by @surenkov in https://github.com/surenkov/django-pydantic-field/pull/13__init__ before calling super().__init__ by @surenkov in https://github.com/surenkov/django-pydantic-field/pull/14Closed: https://github.com/surenkov/django-pydantic-field/issues/12
Full Changelog: https://github.com/surenkov/django-pydantic-field/compare/v0.2.2...v0.2.3
Test support for python 3.11 by @surenkov in https://github.com/surenkov/django-pydantic-field/pull/11
Full Changelog: https://github.com/surenkov/django-pydantic-field/compare/v0.2.1...v0.2.2
The package supports Django starting from 3.1.
The package supports Django starting from 3.1.
Full Changelog: https://github.com/surenkov/django-pydantic-field/compare/v0.2.0...v0.2.1
Python 3.7 + Django 3.2 support by @surenkov in https://github.com/surenkov/django-pydantic-field/pull/10
Full Changelog: https://github.com/surenkov/django-pydantic-field/compare/v0.1.13...v0.2.0
Django Forms schema field by @surenkov in https://github.com/surenkov/django-pydantic-field/pull/9
Full Changelog: https://github.com/surenkov/django-pydantic-field/compare/v0.1.12...v0.1.13
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
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.
Full Changelog: https://github.com/surenkov/django-pydantic-field/compare/v0.1.11...v0.1.12
In the example below, typing linters should enforce type compatibility: ```python class BuildingMeta(pydantic.BaseModel): type: Optional[BuildingTypes
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.
default= argumentIn 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: https://github.com/surenkov/django-pydantic-field/compare/v0.1.10...v0.1.11
Slightly improve inheritance chain, better typings for SchemaField factory function.
Slightly improve inheritance chain, better typings for SchemaField factory function.
Full Changelog: https://github.com/surenkov/django-pydantic-field/compare/v0.1.9...v0.1.10
Attempt to defer ForwardRefs resolution by @surenkov in https://github.com/surenkov/django-pydantic-field/pull/5
Full Changelog: https://github.com/surenkov/django-pydantic-field/compare/v0.1.8...v0.1.9
Django model fields are required to throw django.core.exceptions.ValidationError during .to_python(value) call. Let's stick to that recommendation.
Django model fields are required to throw django.core.exceptions.ValidationError during .to_python(value) call.
Let's stick to that recommendation.
Convert the input value into the expected Python data type, raising django.core.exceptions.ValidationError if the data can't be converted.
Nothing published for this version
I believe that initially introduced error_handler= param is basically doesn't make sense, as it breaks regular validation flow and could be even harmf
I believe that initially introduced error_handler= param is basically doesn't make sense, as it breaks regular validation flow and could be even harmful, as by default it simply suppress errors and writes them in logging. (Re)raising validation errors would be more explicit alternative to that.
I feel it's an overhead to define a full Config class in some cases, like: ```python class Config: json_encoders = ...
I feel it's an overhead to define a full Config class in some cases, like:
class Config:
json_encoders = ...
field: t.List[Schema] = SchemaField(config=Config)
The convenient solution is to pass a dict config instead:
field: t.List[Schema] = SchemaField(config={"json_encoders": ...})
Well, it is now possible to do so.
I'm considering current behavior with forward references resolution as expected. I.e. field schemas should be always defined before field declaration,
I'm considering current behavior with forward references resolution as expected. I.e. field schemas should be always defined before field declaration, otherwise it's not possible to bind a schema to the field during model initialzation. Note though, that annotation should still be declared as string/typing.ForwardRef, as long as prior constraint is satisfied. Main change: now such behavior is explicitly stated with tests.
I tried to defer schema initialzation at a field descriptor level, but this approach did not succeeded with current migrations flow
I tried to defer schema initialzation at a field descriptor level, but this approach did not succeeded with current migrations flow
Nothing published for this version
Now, instead specifying explicit schema, one could write: ```py3 from django.db import Model from django_pydantic_field import SchemaField
Now, instead specifying explicit schema, one could write:
from django.db import Model
from django_pydantic_field import SchemaField
class MyModel(models.Model):
field: list[int] = SchemaField()
The schema will be inferred at model freezing step. Note that it's not possible to specify unresolved forward references at the moment.
In order to support this, I had to introduce a breaking changes in field api defintion: all Pydantic-prefixed classes should be used without this pref…
This is the first minor release of django-pydantic-field, with field-level type definitions:
class Foo(pydantic.BaseModel):
bar: int
class MyModel(models.Model):
meta: list[Foo] = SchemaField(schema=list[Foo])
In order to support this, I had to introduce a breaking changes in field api defintion:
all Pydantic-prefixed classes should be used without this prefix, e.g:
PydanticSchemaField -> SchemaField
PydanticSchemaRenderer -> SchemaRenderer
...
Your coding agent can read these notes before it upgrades. Set up the MCP server →