codingjoe/django-stdimage — pull request #34 by mcnemesis (2014-10-24 05:23:43+00:00)
Title: Make upload_to util classes Django-migrations compatible

Currently, when I try to define my field like this:

> from stdimage import StdImageField
> from stdimage.utils import UploadToClassNameDirUUID
> #...
> image = StdImageField( upload_to = UploadToClassNameDirUUID())

When I try to create migration files (so I can then syncdb), with command:

> ./manage.py makemigrations

The migration script generation would halt at the StdImage fields with the following errors:

raise ValueError("Cannot serialize: %r\nThere are some values Django cannot serialize into migration files.\nFor more, see https://docs.djangoproject.com/en/dev/topics/migrations/#migration-serializing" % value)
ValueError: Cannot serialize:
There are some values Django cannot serialize into migration files.
For more, see https://docs.djangoproject.com/en/dev/topics/migrations/#migration-serializing

And indeed, when you check out the documentation at https://docs.djangoproject.com/en/dev/topics/migrations/#migration-serializing, you find that for *upload_to* arguments that accept callables like in this case, there's need to do something more... A little down on that documentation page, they recommend that for some arbitrary classes to be serializable, one can either implement the decostruct() method or use the in-built decorator @deconstructible to make the class serializable by Django migrations.

So, I added the decorator @deconstructible to the classes in utils above, and when I now run

> ./manage.py makemigrations

It runs without error.

I suggest you integrate this, in order to support Django migrations for fields using StdImageField.