django-ajaximage icon indicating copy to clipboard operation
django-ajaximage copied to clipboard

Upload_to may now be a function

Open briceparent opened this issue 8 years ago • 4 comments

I didn't really test this against older Python/Django versions, but I guess it should work as is. I didn't try either with another type of callable than a function.

I updated the Kitten example, the thumbnails are now put in a random directory (feel free to remove this, of course).

The instance parameter is only available if there is one, as it is done in https://docs.djangoproject.com/fr/1.9/ref/models/fields/#django.db.models.FileField.upload_to.

Hope it helps

briceparent avatar May 12 '16 17:05 briceparent

Also, I don't know how the packaging works, so I didn't do anything related to this.

briceparent avatar May 12 '16 17:05 briceparent

After some testing, I'm sorry to tell that the second argument to the callback function isn't working as it should. Normally, it should be called at the end of the process when we already know the file's name, but as it is now, it is called before the form is even displayed, so there is no way to know the name of the file that will be sent. I supposed it worked, because in my sample data, the field already contained an image, so at the time of creating the form, I already knew the file's name and everything seemed to be good. I'm not sure how to solve this without a way bigger rewrite of the package, and as of now, I'm not going to need it (in my use case, I'm not changing the image's name, just its folder). If there is a need for it, feel free to modify it or to contact me, and if I find some hours to work on it, I'll try to fix this. Brice

briceparent avatar May 13 '16 07:05 briceparent

Actually, the AjaxImageField will have problems on image path if you are not using AdminForm. Since AjaxImageField inherits Field instead of FileField(weird in my opinion), many methods in FileField are now missing, which will cause problems later.

Maybe rewrite the AjaxImageField is a better choice.

Best, Jimmy

jimmykobe1171 avatar May 18 '16 03:05 jimmykobe1171

I totally agree wth you that the field should extend FileField, as it is a file field and it should be able to replace said fields in already existing forms without much trouble. But this project doesn't seem to be unit tested, which makes rewrites kind of hard and dangerous, so I'm no going to do it myself (or at least not now). If I had to do it, I'd probably start a fresh project with unit tests, even if some of them are quite hard to implement with FileFields (maybe this could even be another reason to make a new project, to create an easily unit-tested advanced file field, with some kind of mockup for the uploading part..).

briceparent avatar May 18 '16 06:05 briceparent