#22999: Impossible to generate migration for model with dynamic upload_to field
-------------------------------------+-------------------------------------
Reporter: Kevin Van Wilder | Owner: nobody
<kevin@…> | Status: closed
Type: Bug | Version: 1.7-rc-1
Component: Migrations | Resolution: invalid
Severity: Normal | Triage Stage:
Keywords: | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by charettes):
* status: new => closed
* needs_better_patch: => 0
* resolution: => invalid
* needs_tests: => 0
* needs_docs: => 0
Comment:
> The function defines and returns an inner function which will provide
the complete path based on the instance's user...
> As you can see I have already moved the function into the main module,
yet the error persists.
What you've done is moving the function factory to the main module, as
described by the exception message there's no way Django can reconstruct
the returned inner function.
I suggest you define a callable factory class that implements
`deconstruct` instead:
{{{#!python
from django.utils.deconstruct import deconstructible
@deconstructible
class UploadToStudentDir(object):
path = "students/{0}/{1}{2}"
def __init__(self, sub_path):
self.sub_path = sub_path
def __call__(self, instance, filename):
return path.format(instance.user.username, self.sub_path,
filename)
upload_dir = UploadToStudentDir('committee/reports/')
}}}
This use to work with South because it didn't ''serialize'' the
`upload_to` option of the `FileField` and it subclasses.
I'll mark as invalid since this is a well known limitation of the
migration framework.
--
Ticket URL: <https://code.djangoproject.com/ticket/22999#comment:1>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/096.794f55b47efcf7911fa2b5beeb795ad0%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.