Opened 4 weeks ago
Closed 3 weeks ago
#37023 closed Cleanup/optimization (fixed)
Make XML serializer put each ManyToManyField object on its own line
| Reported by: | Tim Graham | Owned by: | Tim Graham |
|---|---|---|---|
| Component: | Core (Serialization) | Version: | dev |
| Severity: | Normal | Keywords: | |
| Cc: | Triage Stage: | Ready for checkin | |
| Has patch: | yes | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | no | UI/UX: | no |
Description
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>
Change History (5)
comment:1 by , 4 weeks ago
| Has patch: | set |
|---|
comment:2 by , 3 weeks ago
| Triage Stage: | Unreviewed → Accepted |
|---|
I also think this is more readable, thank you for the report and patch
comment:3 by , 3 weeks ago
| Triage Stage: | Accepted → Ready for checkin |
|---|
PR