I am storing files and need a unique file name. I found a suggestion to use django.core.files.storage.get_available_name but I am completely missing something. I tried this:
class MyModel(models.Model):
name = models.CharField( max_length=200, null=True )
filecontent = models.FileField( null=True, upload_to=Storage.get_available_name(name) )
And got the error: TypeError: unbound method get_available_name() must be called with Storage instance as first argument (got CharField instance instead)
which I interpret as meaning that I am trying to run the method on the class but that I need a storage-instance to run it on. There exist something called DefaultStorage which is supposed to be something that "provides lazy access to the current default storage system" but that one does not have the get_available_name
method but only a method _setup
which can't be called on the class either. So how am I supposed to get an instance to work on here?