Opened 6 years ago

Closed 6 years ago

Last modified 5 years ago

#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: UI/UX:

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 Changed 6 years ago by Luke Plant

Needs documentation: unset
Needs tests: unset
Patch needs improvement: unset
Resolution: invalid
Status: newclosed

You are passing the storage class as the argument, instead of an instance of the class, as described in the docs.

comment:2 Changed 6 years ago by jtheoof

I was just gonna close that ticket and say I had a long day :)
Sorry about that.

comment:3 Changed 5 years ago by Jacob

milestone: 1.3

Milestone 1.3 deleted

Note: See TracTickets for help on using tickets.
Back to Top