Thursday, September 9, 2010

Re: upload_to vs FileSystemStorage

On Sep 8, 5:04 am, Dave <kru...@seznam.cz> wrote:
> Hi everyone,
>
> I've found in documentation usage of custom file storage. There it is
> like that (http://docs.djangoproject.com/en/1.2/topics/files/#the-built-in-files...
> ) -
>
> from django.db import models
> from django.core.files.storage import FileSystemStorage
>
> fs = FileSystemStorage(location='/media/photos')
>
> class Car(models.Model):
>     ...
>     photo = models.ImageField(storage=fs)
>
> Notice there is no upload_to attribute in ImageField. I suppose, it's
> quite obvious, because I will set it by attribute location in
> initializing FileSystemStorage object fs. But if I'll do it this way
> it'll rise an error - Error: One or more models did not validate:
> app.mymodel: "image": FileFields require an "upload_to" attribute.
>
> What am I missing? Or is it possiblle to have upload_to somehow set to
> an empty string? So the location would be the same as it is declared
> in the file storage object initialization.

You've basically answered your question - if you read the docs for
FileField you will see upload_to is a required field. It defines path
relative to storage root. so empty string or '/' should do it.

-Preston

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

No comments:

Post a Comment