How to make a drop-down that show images in Django Admin?

Viewed 140

I spent two hours trying to find out how to customize select2 widget in Django admin to implement this simple feature.

I have a model (Article) that contains many other objects (Pictures). Every Picture has a set of FileFields representing the original image file, the thumbnail, post-processed (using Pillow) preview and some meta stuff.

What I'm going to achieve is to be able to upload new images on the Article change page, and select/deselect them in the fancy Select2 dropdown widget.

How can I do that? Should I use ImageField instead of FileField? Should I use inlines and through for ManyToMany relation between Article and Pictures? Should I make my own widget? How do Django admin uses Select2 and how could I pass parameters like "templateResult" to be able to change the look of dropdown items?

Thank you in advance.

0 Answers
Related