Open underdoeg opened 3 years ago
f
should be an instance of an ImageFieldFile
which – in turn – should always have a .name
attribute. I'm not sure what is going on here. I do not have any experience with django-parler, maybe the problem has something to do with it?
The code which crashes is only used for clearing old thumbnails. It's nice that django-imagefield tries cleaning up after itself but if this feature proves problematic we could introduce a flag which deactivates this housekeeping. Does everything else work if you deactivate/remove https://github.com/matthiask/django-imagefield/blob/26f126f3a91b94b2e23dbc6b5da86fdb81ed0bee/imagefield/fields.py#L405-L407 ?
AFAIK parler dynamically creates another model that contains all the translations, and then in the admin panel automatically adds widgets for the related table entry in the current language. usually this works very well, but it does some automated stuff in the background which might cause issues. Everything else seem to work fine though. I'll do some more digging and see if I understand what is going on.
Looks like parler somehow loses the widget and uses the default django image widget. I cannot set the PPOI for the translated image. I feel like it behaves like a regular FileField and loses all "extra features" on clear
That's sad. The django-imagefield widget itself is quite hacky but the activation itself through .formfield(...)
isn't https://github.com/matthiask/django-imagefield/blob/26f126f3a91b94b2e23dbc6b5da86fdb81ed0bee/imagefield/fields.py#L355-L363
So I have no idea what exactly is happening behind the scenes but I kinda managed to work around the issue by adding this to the TranslatedFileAdmin class:
def save_model(self, request, obj, form, change):
if not obj.translated_image_file:
obj.translated_image_file = None
super().save_model(request, obj, form, change)
I have a django cabinet custom File that inherits the TranslatableModel something like:
As hacky as this is, it seems to work. Except when I try to clear the "translated_image_file".
then I get the following erro