See this blog post ... It's pretty old, so maybe everything has changed. But in my experiments they did not. To dynamically change the path to the FileField upload_to file, you must use signals and create custom model fields . Nastya. I canโt imagine that having a dynamic loading path is a special use case that is not covered by the standard Django platform? Am I missing something? Is there any other way to do this?
In essence, I want to do this:
def MyModel(models.Model): fileUpload = models.FileField(upload_to='media/', null=True, blank=True) def save(self, **kwargs):
However, in the 10 different implementations I tried, Django hates them all. For this, in particular, the file is uploaded to the default path 'media/' .
I tried to cross the model parameter for the parameters and pass these parameters to the dict object, create a MyModel object, set the MyModel.fileUpload.upload_to parameter, and then copy the dict to the model and save. Does not work.
I also tried to override the __init__ method, but guess what? It is so early in creating an object that it has not yet defined self.email ! So this will not work.
Any ideas, or should I follow a secret solution outlined in the original link?
source share