
Security News
Django Joins curl in Pushing Back on AI Slop Security Reports
Django has updated its security policies to reject AI-generated vulnerability reports that include fabricated or unverifiable content.
A utility library to integrate and use pydantic with the django orm. This package includes optional sentry integration using sentry-tools
.
This project is currently in the alpha state, even though it can be used in production with some caution. Make sure to fix the version in your requirements.txt and review changes frequently.
pip install djdantic
djdantic.BaseModel
from_orm
method on pydantic schemadjdantic.Field
Field
, used for the custom optionsdjdantic.utils.pydantic_django.transfer_from_orm
djdantic.utils.pydantic_django.transfer_to_orm
If automatic route generation is used, it is not neccessary to use the transfer_*
methods manually.
djdantic.Field
For mapping pydantic schemas to django models, it is required to add at least one of the following extra arguments to each field defined in a pydantic schema.
Using these options on pydantic's
Field
is also possible but deprecated!
orm_field
: django.db.models.Field
(required)myapp.models.MyModel.id
orm_method
: Optional[Callable[[Self], Any] | Callable[[Self, Any], None]]
myapp.models.MyModel.get_calculated_value
scopes
: Optional[List[str]]
read
are taken into account, for write all other scopes are taken into account.is_critical
: Optional[bool]
crt
flag in the jwt token.is_sync_matching_field
: Optional[bool]
sync_matching
to define search fields for the matcher on the field itselfsync_matching
: Optional[List[Tuple[str, django.db.models.Field]]]
transfer_to_orm
with action TransferAction.SYNC
for included sub-records (in a list), used when no id
field is present on the object. Mapping from pydantic field (dot notation for nested fields can be used) to the corresponding django model field.is_sync_matching_field
from djdantic import Field, BaseModel
from ... import models
class User(BaseModel):
email: str = Field(orm_field=models.User.email)
is_password_usable: bool = Field(orm_method=models.User.has_usable_password)
is_superuser: bool = Field(scopes=['access.users.update.any'], is_critical=True, orm_field=models.User.is_superuser)
class UserUpdate(User):
password: Optional[SecretStr] = Field(orm_method=models.User.set_password, is_critical=True)
class OrderUpdate(BaseModel):
items: Optional[List['OrderItemUpdate']] = Field(
orm_field=models.Order.items,
sync_matching=[
('product', models.OrderItem.product),
],
)
FAQs
Utilities to use pydantic with the django orm
We found that djdantic demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Django has updated its security policies to reject AI-generated vulnerability reports that include fabricated or unverifiable content.
Security News
ECMAScript 2025 introduces Iterator Helpers, Set methods, JSON modules, and more in its latest spec update approved by Ecma in June 2025.
Security News
A new Node.js homepage button linking to paid support for EOL versions has sparked a heated discussion among contributors and the wider community.