I have install a fresh wagtail when I try to create a page I'm getting error :
'NoneType' object has no attribute 'model'
My class is :
class CategoryPage(Page):
description_meta = models.CharField(max_length=500, null=True, blank=True)
template = models.CharField(max_length=500, null=True, blank=True, default='_nixaTemplate/category/default.html')
image = models.ImageField(_("Image"), upload_to="img/category/", blank=True, null=True)
display = models.BooleanField(_("Display Post"), default=False )
content_panels = Page.content_panels [
FieldRowPanel([
FieldPanel("description_meta", classname="col-12 col12"),
FieldPanel("template", classname="col-12 col12"),
ImageChooserPanel("image", classname="full"),
]),
]
when I try to create Category Page I get that message
CodePudding user response:
ImageChooserPanel
needs to be used with a ForeignKey
to the Image model, not an ImageField
. This is because Django's ImageField
field type just provides a plain file upload, but in Wagtail images are database objects in their own right that can be re-used, given titles, organised into collections and so on.
class CategoryPage(Page):
description_meta = models.CharField(max_length=500, null=True, blank=True)
template = models.CharField(max_length=500, null=True, blank=True, default='_nixaTemplate/category/default.html')
image = models.ForeignKey(("wagtailimages.Image"), blank=True, null=True, on_delete=models.SET_NULL)
display = models.BooleanField(_("Display Post"), default=False )
content_panels = Page.content_panels [
FieldRowPanel([
FieldPanel("description_meta", classname="col-12 col12"),
FieldPanel("template", classname="col-12 col12"),
ImageChooserPanel("image", classname="full"),
]),
]
Alternatively, if you just want a plain file upload field here, you can use FieldPanel
instead of ImageChooserPanel
, but then the images will exist outside of the Wagtail image library and the standard image functionality (such as the {% image %}
template tag) won't be usable for them.