Django Custom Image Upload Field With Dynamic Path
Solution 1:
You don't need a custom field for this. As the documentation shows, upload_to
can be a callable, which is passed the instance and returns a path which determines where the field is saved.
I'm not sure what you mean about the width and height parameters. These are calculated from the image in any case. If you specify height_field
and width_field
in the field definition, the corresponding fields will be filled with the values of the image's height and width when the image is uploaded.
Solution 2:
Your can change the storage of a FileField using the location property.
form_name.photo.storage.location = upload_dir_path
It works for the FileField and maybe it will also work for your custom image field if you inherit the Django's ImageField.
Solution 3:
all info for uploading:
http://docs.djangoproject.com/en/dev/topics/files/
and info on resizing
i'll hope it helps
EDIT: all you need i think is: http://code.google.com/p/django-stdimage/ but i don't know if it works on current version.
Post a Comment for "Django Custom Image Upload Field With Dynamic Path"