#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.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion visit 
https://groups.google.com/d/msgid/django-updates/0107019e241e37fc-6245d82c-a761-41ff-8072-c4500b555557-000000%40eu-central-1.amazonses.com.

Reply via email to