Skip to content

'bool' object has no attribute 'name' when using the image field with parler TranslatableModel #9

@underdoeg

Description

@underdoeg

I have a django cabinet custom File that inherits the TranslatableModel something like:

# models.py
class File(TranslatableModel, AbstractFile, ImageMixin):
    FILE_FIELDS = ['image_file']

    # Add caption and copyright, makes FileAdmin reuse easier.
    caption = models.CharField(
        "Interner Titel",
        max_length=512,
        blank=True,
    )

    copyright = models.CharField(
        "Copyright",
        max_length=512,
        blank=True,
    )

    translations = TranslatedFields(
        translated_image_file=ImageField(
            "Übersetztes Bild",
            auto_add_fields=True,
            upload_to=UPLOAD_TO,
            blank=True,
            max_length=1000,
        )
    )

#admin.py

@admin.register(File)
class TranslatedFileAdmin(TranslatableAdmin, FileAdmin):
    top_fields = ["folder", "caption", "translated_image_file"]

    def get_fieldsets(self, request, obj=None):
        res = super().get_fieldsets(request, obj)
        res[0][1]["fields"].append('translated_image_file')
        return res

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

  File "python3.9/site-packages/imagefield/fields.py", line 405, in _generate_files
    if previous and previous[0] and previous != (f.name, f._ppoi()):
AttributeError: 'bool' object has no attribute 'name'

Metadata

Metadata

Assignees

No one assigned

    Labels

    help wantedExtra attention is needed

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions