Code

Opened 3 years ago

Closed 3 years ago

Last modified 3 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.

Attachments (0)

Change History (3)

comment:1 Changed 3 years ago by lukeplant

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Resolution set to invalid
  • Status changed from new to closed

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

comment:2 Changed 3 years ago by jtheoof

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

comment:3 Changed 3 years ago by jacob

  • milestone 1.3 deleted

Milestone 1.3 deleted

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.