Opened 16 years ago

Closed 16 years ago

#10948 closed (duplicate)

pre_save used on FileField/ImageField doesn't work

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

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

Change History (1)

comment:1 by Karen Tracey, 16 years ago

Resolution: duplicate
Status: newclosed

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

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