Re: [Django] #36986: Add model field serialization API (was: Add Field.serialize_to_python/xml() and deserialize_from_python/xml() hooks)

4 views
Skip to first unread message

Django

unread,
May 13, 2026, 9:33:46 PMMay 13
to django-...@googlegroups.com
#36986: Add model field serialization API
-------------------------------------+-------------------------------------
Reporter: Tim Graham | Owner: Tim
Type: | Graham
Cleanup/optimization | Status: assigned
Component: Core | Version: dev
(Serialization) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Tim Graham):

* summary:
Add Field.serialize_to_python/xml() and deserialize_from_python/xml()
hooks
=> Add model field serialization API

Comment:

Regarding the initially proposed `Field.serialize_to_python()`,
`serialize_to_xml()`, `deserialize_from_python()`, and
`deserialize_from_xml()` methods, Simon suggested:

> my immediate reaction is that making model fields serializer aware
instead of making serializers field aware seems a step in the wrong
direction.
>
> I think that adding public methods to `models.db.Field` should have a
pretty high bar, particularly when it doesn't relate to the ORM, and I
don't think that XML serialization of fixtures meets that criteria.

I proposed an alternative API
([https://github.com/django/django/pull/21233 PR]) which looks like this:
{{{#!python
class FieldSerializer:
@classmethod
def serialize(cls, field, obj, serializer):
...

@classmethod
def deserialize(cls, field, field_node, deserializer):
...
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/36986#comment:15>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
Reply all
Reply to author
Forward
0 new messages