Opened 9 years ago

Closed 9 years ago

#493 closed defect (fixed)

[patch] FileField.get_foo_url returns absolute path instead url

Reported by: nesh <nesh [at] studioquattro [dot] co [dot] yu> Owned by: adrian
Component: Metasystem Version:
Severity: normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

Quick fix:

Index: django/core/meta/__init__.py
===================================================================
--- django/core/meta/__init__.py        (revision 635)
+++ django/core/meta/__init__.py        (working copy)
@@ -999,7 +999,8 @@
 def method_get_file_url(field, self):
     if getattr(self, field.name): # value is not blank
         import urlparse
-        return urlparse.urljoin(settings.MEDIA_URL, getattr(self, field.name)).replace('\\', '/')
+        fname = getattr(self, field.name)[len(settings.MEDIA_ROOT):] # name is stored with filesystem full path
+        return urlparse.urljoin(settings.MEDIA_URL, fname).replace('\\', '/')
     return ''
 
 def method_get_file_size(field, self):

Change History (1)

comment:1 Changed 9 years ago by nesh <nesh [at] studioquattro [dot] co [dot] yu>

  • Resolution set to fixed
  • Status changed from new to closed

How stupid of me ;D

My custom function which rename files before posting is storing full paths in image field. When I stored relative paths everything is working OK.

It seems that I need to read documentation again :)

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