Search code examples
djangodjango-south

Creating a Django South data migration that will populate ImageField from table data


Sorry about the contrived title, let me explain. I have a Django model with filename and extension fields, and then there's a static URL where my files are hosted (on S3, not in the database).

I created a South schema migration to add an ImageField to my table.

Is it possible to create a South data migration that will populate the ImageField for each object, starting from my static URL, the filename field, and the extension field?


Solution

  • This is as simple as:

    my_image.my_imagefield = my_image.filename + my_image.extension
    my_image.save()
    

    as the static part of the URL will be handled by Django STATIC_URL automatically.