[Django] #37023: Make XML serializer put each ManyToManyField object on its own line

10 views
Skip to first unread message

Django

unread,
Apr 4, 2026, 6:28:11 PM (4 days ago) Apr 4
to django-...@googlegroups.com
#37023: Make XML serializer put each ManyToManyField object on its own line
-------------------------------------+-------------------------------------
Reporter: Tim | Owner: Tim Graham
Graham |
Type: | Status: assigned
Cleanup/optimization |
Component: Core | Version: dev
(Serialization) |
Severity: Normal | Keywords:
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
The XML serializer serializes many-to-many relations on a single line:

`<field name="categories" rel="ManyToManyRel"
to="serializers.category"><object pk="1"></object><object
pk="2"></object></field>`

which isn't very readable. I suggest this format instead:

{{{
<field name="categories" rel="ManyToManyRel" to="serializers.category">
<object pk="1"></object>
<object pk="2"></object>
</field>
}}}

Although not strictly required for this ticket, the first commit in my PR
will remove fixed values in the XML serializer's `indent()` calls (e.g.
`self.indent(1)`) which are unfriendly to "nested fields" like Django
MongoDB Backend's EmbeddedModelField which I'd like to serialize like
this:
{{{
<django-objects version="1.0">
<object model="serialization_.book">
<field name="name" type="CharField">Hamlet</field>
<field name="author" type="EmbeddedModelField">
<object model="serialization_.author">
<field name="id" type="ObjectIdAutoField"><None></None></field>
<field name="name" type="CharField">Shakespeare</field>
<field name="age" type="IntegerField">55</field>
<field name="address" type="EmbeddedModelField">
<object model="serialization_.address">
<field name="id"
type="ObjectIdAutoField"><None></None></field>
<field name="city" type="CharField">NYC</field>
<field name="state" type="CharField">NY</field>
<field name="zip_code"
type="IntegerField"><None></None></field>
</object>
</field>
</object>
</field>
</object>
</django-objects>
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/37023>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Apr 4, 2026, 6:38:39 PM (4 days ago) Apr 4
to django-...@googlegroups.com
#37023: Make XML serializer put each ManyToManyField object on its own line
-------------------------------------+-------------------------------------
Reporter: Tim Graham | Owner: Tim
Type: | Graham
Cleanup/optimization | Status: assigned
Component: Core | Version: dev
(Serialization) |
Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Unreviewed
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Tim Graham):

* has_patch: 0 => 1

Comment:

[https://github.com/django/django/pull/21056 PR]
--
Ticket URL: <https://code.djangoproject.com/ticket/37023#comment:1>

Django

unread,
Apr 6, 2026, 2:20:08 AM (3 days ago) Apr 6
to django-...@googlegroups.com
#37023: Make XML serializer put each ManyToManyField object on its own line
-------------------------------------+-------------------------------------
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 Sarah Boyce):

* stage: Unreviewed => Accepted

Comment:

I also think this is more readable, thank you for the report and patch
--
Ticket URL: <https://code.djangoproject.com/ticket/37023#comment:2>

Django

unread,
Apr 6, 2026, 1:03:05 PM (2 days ago) Apr 6
to django-...@googlegroups.com
#37023: Make XML serializer put each ManyToManyField object on its own line
-------------------------------------+-------------------------------------
Reporter: Tim Graham | Owner: Tim
Type: | Graham
Cleanup/optimization | Status: assigned
Component: Core | Version: dev
(Serialization) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Jacob Walls):

* stage: Accepted => Ready for checkin

--
Ticket URL: <https://code.djangoproject.com/ticket/37023#comment:3>

Django

unread,
Apr 6, 2026, 1:04:58 PM (2 days ago) Apr 6
to django-...@googlegroups.com
#37023: Make XML serializer put each ManyToManyField object on its own line
-------------------------------------+-------------------------------------
Reporter: Tim Graham | Owner: Tim
Type: | Graham
Cleanup/optimization | Status: closed
Component: Core | Version: dev
(Serialization) |
Severity: Normal | Resolution: fixed
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Jacob Walls <jacobtylerwalls@…>):

* resolution: => fixed
* status: assigned => closed

Comment:

In [changeset:"33bfc66add643f49d466c5a646989ad91677753d" 33bfc66]:
{{{#!CommitTicketReference repository=""
revision="33bfc66add643f49d466c5a646989ad91677753d"
Fixed #37023 -- Made XML serializer put each ManyToManyField object on its
own line.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/37023#comment:5>

Django

unread,
Apr 6, 2026, 1:04:59 PM (2 days ago) Apr 6
to django-...@googlegroups.com
#37023: Make XML serializer put each ManyToManyField object on its own line
-------------------------------------+-------------------------------------
Reporter: Tim Graham | Owner: Tim
Type: | Graham
Cleanup/optimization | Status: assigned
Component: Core | Version: dev
(Serialization) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by Jacob Walls <jacobtylerwalls@…>):

In [changeset:"eb244b011716d62b22dbca45f0a621a6192cad67" eb244b01]:
{{{#!CommitTicketReference repository=""
revision="eb244b011716d62b22dbca45f0a621a6192cad67"
Refs #37023 -- Removed hardcoded indent levels from XML serializer.

This facilitates nested fields and objects.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/37023#comment:4>
Reply all
Reply to author
Forward
0 new messages