I have a model:
class Photo(models.Model):
filename = models.CharField(max_length=240)
And a corresponding MySQL table, filled with filenames (copied from an existing table).
In the future I may want to upload new photos to the model via admin. Is it possible to evolve the current model into something with ImageFields and integrate my legacy data?
It is possible, assuming the current
filenamefield in your model contains the full path to the actual file, you can add a new field (ImageField) to your model and migrate it using South, then write a script to update your data.A skeleton example,
And then remove the old
filenamefield via South. Take a look at Django’sFileFieldfirst for more information, sinceImageFieldessentially inherits all of the former’s attribute and methods. (see https://docs.djangoproject.com/en/1.3/ref/models/fields/#django.db.models.FileField)