0๐
The way that the dumpdata
management command does it with fixtures is to dump an array of the PK values for the objects in the ManyToMany field. The instances themselves are dumped separately.
For example:
{
"pk": 365,
"model": "tree.tree",
"fields": {
"label": "Root",
"subtrees": [
367,
368
]
}
Iโd start by looking into that implementation and see what, if anything, you can reuse from it.
๐คJim K.
Source:stackexchange.com