Code

Opened 5 years ago

Closed 5 years ago

#10948 closed (duplicate)

pre_save used on FileField/ImageField doesn't work

Reported by: lstep Owned by: nobody
Component: File uploads/storage Version: master
Severity: Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

If I set a signal that intercepts as pre_save and try to access a FileField/ImageField's path, I don't get the same result. It seems the 'upload_to' attribute is not taken into account!

Here's a very simple example to show the problem:

  • settings.py (relevant parts only):

MEDIA_ROOT = '/tmp/static'
MEDIA_URL = '/static/'

  • models.py:

from django.db import models
from django.db.models import signals

class MyModel(models.Model):

myfile = models.FileField(upload_to="uploads")

def intercept(sender, instance, signal, *args, kwargs):

print instance.myfile
print instance.myfile.path
print instance.myfile.url

signals.pre_save.connect(intercept, sender=MyModel)

  • In Django 1.0.2-final:

uploads/a.flv
/tmp/static/uploads/a
.flv
/static/uploads/a.flv

  • In Django 1.1+ (1.1beta and latest SVN version 1.1 beta 1

SVN-10367):

a.flv
/tmp/static/a.flv
/static/a.flv

Please the associated thread on http://groups.google.com/group/django-developers/browse_thread/thread/ce20f196f5e85296

Attachments (0)

Change History (1)

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

I did create a ticket for this a while ago: #10788. Apologies for not noting that in the dev discussion thread.

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.