How to add multiple images to a model?

853 views Asked by At

Wagtail

My model code:

class HomePage(Page):

    images = models.ImagesField(max_count = 20)  // How to do it right?
   
    content_panels = Page.content_panels + [
        ImagesChooserPanel('images'),
    ]

How it should look

Please help!

2

There are 2 answers

0
LOVE USA On BEST ANSWER

Solved by streamfield

images =  StreamField([
        ('image', ImageChooserBlock()),
    ])
0
Dakshesh Jain On

(sadly)You can't such thing as

images = models.ImagesField(max_count = 20)  

but there are multiple ways you can associate multiple images to the same model as

  1. using image1 = models.ImagesField(upload_tp='somewhere') image2 = models.ImagesField(upload_tp='somewhere')
  2. second associate model to a different model using a foreign key and use the first way