Wait, I just looked into this further, and discovered that the ordering of fields was made deterministic for all serializers in #24558 <https://code.djangoproject.com/ticket/24558> - this was released in Django 1.9! Enjoy👌
On 7 March 2017 at 22:23, Adam Johnson <m...@adamj.eu> wrote: > Ah yes, PyYAML just does this. It can be disabled by passing a different > option to yaml.dump (I think default_flow_style=False) but that would be > similar to changing the JSON serializer.. > > On 6 March 2017 at 16:53, Brice PARENT <cont...@brice.xyz> wrote: > >> >> Le 06/03/17 à 15:44, Brice PARENT a écrit : >> >>> Le 06/03/17 à 14:28, Adam Johnson a écrit : >>> >>>> PyYAML sorts keys by default, so if you use the YAML serializer that >>>> should work for your usecase. >>>> >>> I think it will become my new default ! >>> >> It appears that the rendered format is not very consistent, or at least >> it's what I've found. Yaml seems to offer a short and a long syntax. >> I tried with 2 models, one from stock Django (flatpages), which seems to >> give something that corresponds to my needs, and one with a custom one, >> where the used syntax doesn't create a new line for each field. (I edited >> the outputs to focus on the idea and remove irrelevant contents). >> ./manage.py dumpdata --format yaml --indent 4 flatpages >> - fields: >> content: '<p>First line.</p> >> <p>Second line</p>' >> enable_comments: false >> registration_required: false >> sites: [1] >> template_name: '' >> title: Multiline >> url: /my/test/ >> model: flatpages.flatpage >> pk: 13 >> >> ./manage.py dumpdata --format yaml --indent 4 myapp >> - fields: {content: "<p>First line.</p>\r\n\r\n<h3>Second line</h3>\r\ >> \n", module: 1, position: 1, summary: "<h3>First line.</h3>\r\ >> \n\r\n<h3>Second line</h3>\r\", title: "My title"} >> model: myapp.mymodel >> pk: 1 >> >> So with the same command, I've gotten two formats, one that is >> git-friendly, and one that isn't. I haven't yet looked at the source code >> on why it chose to use one syntax over the other though. >> >> Brice >> >> -- >> You received this message because you are subscribed to the Google Groups >> "Django developers (Contributions to Django itself)" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to django-developers+unsubscr...@googlegroups.com. >> To post to this group, send email to django-developers@googlegroups.com. >> Visit this group at https://groups.google.com/group/django-developers. >> To view this discussion on the web visit https://groups.google.com/d/ms >> gid/django-developers/7056c260-d57e-e465-b087-fc1e06762402%40brice.xyz. >> >> For more options, visit https://groups.google.com/d/optout. >> > > > > -- > Adam > -- Adam -- You received this message because you are subscribed to the Google Groups "Django developers (Contributions to Django itself)" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-developers+unsubscr...@googlegroups.com. To post to this group, send email to django-developers@googlegroups.com. Visit this group at https://groups.google.com/group/django-developers. To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/CAMyDDM2onJFJGAFC5UGiJpmKth%3DnKeHVjYk%3Dv-GMYCrk-%3DqR_A%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.