No image chooser for image field in admin
robslotboom opened this issue · comments
Issue Summary
The folowing code results in a select rather than an image chooser.
class PageMixin(ImageMixin, Page, RevisionMixin):
image = models.ForeignKey(
'wagtailimages.Image',
verbose_name = 'image',
help_text = 'help'),
null = True,
blank = True,
on_delete = models.SET_NULL,
related_name = '+'
)
image_panels = [
FieldPanel('image')
]
edit_handler = TabbedInterface(
[
...
ObjectList(image_panels, 'image'),
]
)
Technical details
- Python version: 3.12.
- Django version: 5.0.4.
- Wagtail version: 6.0.2.
- Browser version: Safari 17.4.1.
Hi @robslotboom - thanks for the report.
The code you've provided isn't complete (it doesn't include the definition of ImageMixin, and adding RevisionMixin to a Page class seems wrong as pages already have revision history built in), so this doesn't give us enough information to replicate the issue. Please can you provide a standalone code snippet that demonstrates the issue?
Hi Matt, My RevisionMixin is as follows:
#_____________________________________________________________________________
class RevisionMixin(object):
def delete_irrelavant_revisions(self):
keep_num = NUMBER_OF_REVISIONS
revisions_to_keep = self.revisions.order_by('-created_at', '-id').all()[:keep_num]
ids = [revision.id for revision in revisions_to_keep]
if ids:
result_num, result_dict = self.revisions.exclude(pk__in=ids).delete()
I call it in chron scripts to delete old revisions
And the ImageMixin is as follows:
#_____________________________________________________________________________
class ImageMixin(models.Model):
image = models.ForeignKey(
'wagtailimages.Image',
verbose_name = _('image'),
help_text = _('some help...'),
null = True,
blank = True,
on_delete = models.SET_NULL,
related_name = '+'
)
class Meta:
abstract = True
@cached_property
def promo_image(self):
return self.image
This mixin also has some functions to return thumb-urls etc.
Thanks - please can you try placing all the above code into the models.py of a fresh Wagtail project, and confirm whether the issue still appears?
Hi Matt, Found the problem.
I configured a base_form_class for the page model which used some form mixins which were inheriting from forms.Form.
These mixins had a class Meta in them.
After removing Meta from the mixins the image chooser was back :-D