why is unable to import the ImageChooserPanel from wagtail.image.edit_handlers

116 Views Asked by At

this is the code right in wagtail as i can't import ImageChooserPanel from wagtail.images.edit_handlers as i also used this from wagtail.images.models import Image but cant still import it and it is showing error.

this is the error i am getting after searching in google, chat gpt they are showing me the same thing but i am not getting error in vs code in models.py but i am getting error in live server while hosting it like this

this is the error i am getting if u see in the last line

i try to solve the error in python it did went away but not in when i run in livehost and i am expecting somehow to import the ImageChooserPanel

# Import necessary modules and classes
from django.db import models
from wagtail.models import Page
from wagtail.admin.panels import FieldPanel, PageChooserPanel
from wagtail.images.models import Image
from wagtail.images.edit_handlers import ImageChooserPanel

# Define a custom Wagtail Page model for the homepage
class Homepage(Page):
    # Define a CharField for subheading text under the banner title
    lead_text = models.CharField(
        max_length=140, 
        blank=True, 
        help_text='Subheading text under the banner title',
    )

    # Define a ForeignKey for an optional page to link to
    button = models.ForeignKey(
        'wagtailcore.page',
        blank=True,
        null=True,
        related_name='+',
        help_text='Select an optional page to link to',
        on_delete=models.SET_NULL, 
    )

    # Define a CharField for button text with a default value
    button_text = models.CharField(       
        max_length=50,
        default='Read More',
        blank=False,
        help_text='Button text',
    )

    # Define a ForeignKey for the banner background image
    banner_background_image = models.ForeignKey(
        'wagtailimages.Image',
        blank=True,
        null=True,
        related_name='+',
        help_text='The banner background image',
        on_delete=models.SET_NULL,
    )

    # Define content panels for Wagtail admin interface
    content_panels = Page.content_panels + [
        FieldPanel("lead_text"),
        PageChooserPanel("button"),
        FieldPanel("button_text"),
        ImageChooserPanel("banner_background_image"),
    ]```
1

There are 1 best solutions below

1
gasman On

ImageChooserPanel was deprecated in Wagtail 3.0 and fully removed in Wagtail 5.0. You should use FieldPanel instead.