#14911 closed (invalid)
Custom Storage System not working properly
| Reported by: | jtheoof | Owned by: | nobody |
|---|---|---|---|
| Component: | File uploads/storage | Version: | 1.2 |
| Severity: | Keywords: | storage ImageField Custom | |
| Cc: | Triage Stage: | Unreviewed | |
| Has patch: | no | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | no | UI/UX: | no |
Description
As described in django doc, it should be possible to override the default storage system.
from django.db import models
from django.core.files.storage import FileSystemStorage
fs = FileSystemStorage(location='/media/photos')
class Car(models.Model):
...
photo = models.ImageField(storage=fs)
Also, by default, the DefaultStorage is the FileSystemStorage in django.core.files.storage
But specifying storage at model field level is rising an exception see this code:
import datetime
from django.core.files.storage import FileSystemStorage
from django.db import models
class ModelTest(models.Model):
image = models.ImageField(upload_to='test', storage=FileSystemStorage)
date_created = models.DateTimeField(default=datetime.datetime.now)
I'm getting the following exception at view level:
unbound method get_valid_name() must be called with FileSystemStorage instance as first argument (got unicode instance instead)
when I try to upload a file in the admin interface.
If I remove the storage parameter, it works fine.
Change History (3)
comment:1 by , 15 years ago
| Resolution: | → invalid |
|---|---|
| Status: | new → closed |
comment:2 by , 15 years ago
I was just gonna close that ticket and say I had a long day :)
Sorry about that.
You are passing the storage class as the argument, instead of an instance of the class, as described in the docs.