Django fixtures with ManyToMany fields

This evening I learned how to set up a ManyToMany value in a fixture.  I ended up using the “dumpdata” feature of manage.py to figure out the syntax.

I’ve got a ManyToMany field for one of my models called “district”.  I wanted to link the model instance to one district object (district ID #1):

"district": [1]
If I wanted add them to more than one district it would look like this:
"district": [1, 2, 5]

Leave a Comment


NOTE - You can use these HTML tags and attributes:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>