Hello All,

I am being very perplexed and annoyed by models.FileField database
fields. I have two problems:

1. The filefield.url attribute gives the path on my hard disk, not the
internet URL that the file is being served to. The filefield.path and
filefield.name attributes also give the exact same result as .url.

2. How am I supposed to make a form where the user uploads something?
I think I can hack something together by reverse-engineering the Admin
page, and by looking around on the internet, but I don't see one good
and simple example. I want simple.

My setup:

Mac OS X 10.5.8
Django 1.0.2
Development server only, at the moment.

#In settings.py:
MEDIA_URL = '/media/'
MEDIA_ROOT = '/Users/me/publications/'

#In models.py:
class Publication(models.Model):
        pdf = models.FileField(upload_to='pdf')

#In urls.py:
urlpatterns += patterns('',
       (r'^media/(?P<path>.*)$', 'django.views.static.serve',
{'document_root': '/Users/me/publications'}),
)

I think that's all the relevant stuff. Some findings/example tasks:

I upload a file, essay.pdf, using the Django Admin console.
http://127.0.0.1:8000/media/pdf/essay.pdf
#It works, there it is.

In the shell, (python manage.py shell):
>>>essay.pdf.path
u'/Users/me/publications/pdf/essay.pdf'
>>>essay.pdf.name
u'/Users/me/publications/pdf/essay.pdf'
>>>essay.pdf.url
u'/Users/me/publications/pdf/essay.pdf'

Now that doesn't seem quite right. I have seen working examples, I
even made one once, I don't know what is wrong here.

Thanks.
--~--~---------~--~----~------------~-------~--~----~
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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to