Search code examples
djangoimagedjango-fixtures

Images in Django fixtures?


I was looking at Django fixtures in the docs, there was no mention of preloading images into the database. I can't be the only who needed to do this. Is this possible? If so how? If not, are there any workarounds available?

Please and thank you.


Solution

  • Yes, it's possible. You have to put your image in your project MEDIA_ROOT. In fixtures it will look like

    [{
        "pk": 1,
        "model": "pictures.picture",
        "fields": {
            "image": "/media/gebakken_kip_met_korianderrijst_1152_x_1728.png"
    
        }
    }]