Re: FileField; url oddness

2008-10-31 Thread csingley



On Oct 31, 7:05 pm, "Marty Alchin" <[EMAIL PROTECTED]> wrote:

> My guess is that you need a trailing slash here. Without it, the
> urljoin() function doesn't know 'reports' is a directory, so  it
> strips 'reports' out and replaces it with the path from the database.
> This is why your settings.py includes the following comment above the
> MEDIA_URL setting: "Make sure to use a trailing slash if there is a
> path component"
>
> -Gul

Thanks a lot!
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: FileField; url oddness

2008-10-31 Thread Marty Alchin

On Fri, Oct 31, 2008 at 1:42 PM, csingley <[EMAIL PROTECTED]> wrote:
> report_storage = ReportStorage(location='%s/reports' %
> settings.MEDIA_ROOT,
>base_url=settings.MEDIA_URL
> +'reports')

My guess is that you need a trailing slash here. Without it, the
urljoin() function doesn't know 'reports' is a directory, so  it
strips 'reports' out and replaces it with the path from the database.
This is why your settings.py includes the following comment above the
MEDIA_URL setting: "Make sure to use a trailing slash if there is a
path component"

-Gul

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



FileField; url oddness

2008-10-31 Thread csingley

Hi, I've got a model defined like so:
"""
from django.conf import settings
from django.db import models
from django.core.files.storage import FileSystemStorage

class ReportStorage(FileSystemStorage):
@staticmethod
def filepath(instance, filename):
subdir = '/'.join((instance.account.client.username,
instance.account.number))
filename = '%s.pdf' % instance.slug
return '/'.join((subdir, filename))

report_storage = ReportStorage(location='%s/reports' %
settings.MEDIA_ROOT,
base_url=settings.MEDIA_URL
+'reports')
class Report(models.Model):
content = models.FileField(storage=report_storage,
upload_to=report_storage.filepath)
"""

However, the urls aren't being generated as expected.  Here's an
interactive session:
"""
In [1]: from apps.userhomes.models import Report

In [2]: foo = Report.objects.get(id=1)

In [3]: foo.content.url
Out[3]: u'/media/test1/111/2008q3.pdf'

In [4]: foo.content.storage.base_url
Out[4]: '/media/reports'
"""

I'd expect that 3rd output to be  u'/media/reports/
test1/111/2008q3.pdf' instead; FileSystemStorage.url() specifies that
the base_url should be used.

Can anybody give me a clue what's going on here?

TIA

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---