Code

Opened 5 years ago

Closed 5 years ago

Last modified 5 years ago

#11855 closed (duplicate)

ImageField .path attribute does not take into account upload_to pre-save - Django 1.1

Reported by: djm Owned by: nobody
Component: File uploads/storage Version: 1.1
Severity: Keywords: FileField, ImageField, path, attribute
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

I'm not sure if this was an intentional change with Django and I couldn't find a related ticket/general information on the subject so here goes:

With Django 1.0, when overriding the save() method on model that has an ImageField (let's name the field "logo"), the full (absolute) system path of the file was available by using self.logo.path before and after calling super(ModelName, self).save().

On a clean install of 1.1 however, with the field logo = models.ImageField(upload_to="uploads/img/logos/") and save() method as below:

def save(self):
    print self.logo.path
    super(Exhibitor, self).save()
    print self.logo.path

the following is observed:

/home/djm/sites/projectname/media/Firefox_wallpaper.png
/home/djm/sites/projectname/media/uploads/img/logos/Firefox_wallpaper_.png

As you can see, the "upload_to" part of the path is missing pre-save. Is this right - or should I just not be trying to use the .path attribute pre-save?

Attachments (0)

Change History (3)

comment:1 Changed 5 years ago by kmtracey

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

See #10788 and http://docs.djangoproject.com/en/dev/releases/1.1/#names-of-uploaded-files-are-available-later

It wasn't actually an intentional change but it was intentionally decided not to try to restore the old behavior.

comment:2 Changed 5 years ago by djm

I have read that page many a time and I still can't see how I missed that glaring fact. Many thanks.

comment:3 Changed 5 years ago by djm

  • Cc mail@… removed

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.