Reusing Wagtail's image chooser in vanilla Django admin? Possible? Horrifyingly bad idea?

269 views
Skip to first unread message

Chris Adams

unread,
Apr 22, 2016, 11:24:48 AM4/22/16
to Wagtail support
Hi there,

Is there a way of using the Wagtail image chooser from outside of Wagtail Admin, for example when you're editing a model using the normal django admin?

In my case, I have a web app where users have a number of established workflows which rely heavily on some features of Django admin, but where the public facing content is an ideal for managing using Wagtail's admin workflow.

So, I'm hoping I can make the case for people to adopt Wagtail for things that look more like traditional content (we're looking to overhaul how public content is managed), and for the rest, stay with Django admin for the time being.

However, there are cases when images are likely to be reused across the two workflows, and I really like the UX for Wagtails's image chooser.

From what I can see, it looks like someone else has tried to do a similar thing, outlined in this post:


However the editors_pick.html template no longer is there for me to look over to see how it worked.

My best guess so far, based on what I've learned

I can see some code which looks recognisable here (I've never really hacked on Wagtail before), based on the routes I'm seeing:


I've got a rough idea about how I'd go about doing this now, but before I embark on such a quest, has someone already done this, and made these choosers accessible from the vanilla django admin?

Where be dragons?

As I mentioned before, I'm not too familiar with Wagtails innards, so this whole enterprise could be a terrible idea - if it does sound like it, and there is a whole thicket of gotchas ahead of me (I just want a consistent upload and choosing experience for images), it would be nice to hear from someone who's got the scars already :)

Many thanks to everyone who's worked on Wagtail so far, it's a *lovely* project.

Chris

Matthew Westcott

unread,
Apr 22, 2016, 11:56:45 AM4/22/16
to wag...@googlegroups.com
Hi Chris,

The discussion at https://groups.google.com/forum/#!searchin/wagtail/upload/wagtail/c_bHv05g9aA/ZYlDVZE1PlwJ is a bit of a red herring, and not really applicable to what you're doing... on that occasion, they wanted to use the image chooser still within the Wagtail admin, but outside the page/snippet edit forms. This used to require extra hacks, but doesn't any more - we've since converted the image / page / document / snippet choosers into ordinary Django form widgets. In the case of the image chooser, you can import this as:

from wagtail.wagtailimages.widgets import AdminImageChooser

(The editor's pick code still exists - it's now under https://github.com/torchbox/wagtail/tree/master/wagtail/contrib/wagtailsearchpromotions - but it won't tell you very much, now that the aforementioned hacks have been eliminated...)

Unfortunately, while the choosers are now standard Django widgets, they do still depend on various bits of Wagtail-admin-specific CSS / JS, and I suspect it'll be difficult to make them work outside of Wagtail admin.

Cheers,
- Matt

Matthew Westcott

unread,
Apr 22, 2016, 11:56:46 AM4/22/16
to wag...@googlegroups.com
Hi Chris,

The discussion at https://groups.google.com/forum/#!searchin/wagtail/upload/wagtail/c_bHv05g9aA/ZYlDVZE1PlwJ is a bit of a red herring, and not really applicable to what you're doing... on that occasion, they wanted to use the image chooser still within the Wagtail admin, but outside the page/snippet edit forms. This used to require extra hacks, but doesn't any more - we've since converted the image / page / document / snippet choosers into ordinary Django form widgets. In the case of the image chooser, you can import this as:

from wagtail.wagtailimages.widgets import AdminImageChooser

(The editor's pick code still exists - it's now under https://github.com/torchbox/wagtail/tree/master/wagtail/contrib/wagtailsearchpromotions - but it won't tell you very much, now that the aforementioned hacks have been eliminated...)

Unfortunately, while the choosers are now standard Django widgets, they do still depend on various bits of Wagtail-admin-specific CSS / JS, and I suspect it'll be difficult to make them work outside of Wagtail admin.

Cheers,
- Matt


On 22 Apr 2016, at 16:24, Chris Adams <ch...@productscience.co.uk> wrote:

Chris Adams

unread,
Apr 22, 2016, 1:12:16 PM4/22/16
to Wagtail support
Wow, thanks for the fast response Matt!

I think this gives me enough to go on and play with, but it looks like I have two options

1. Use the `modeladmin` wagtail contrib model[1] to expose only the necessary fields of the model we care about for that workflow, and have this live in Wagtail admin (right now, these are represented in a "publicly visible" fieldset in Django admin, so it's not such a bad fit anyway).

2. See if I can get the relevant form widgets[2] working, bearing in mind the Wagtail-admin-specific CSS / JS caveats mentioned before.

Of the two, option 1 is looking quite attractive right now, and probably fits my use case.

Yay wagtail!

Have a good weekend, y'all.


[2]: from wagtail.wagtailimages.widgets import AdminImageChooser

Tom Dyson

unread,
Apr 22, 2016, 2:47:03 PM4/22/16
to Wagtail support
Hi Chris

modeladmin definitely sounds like the way to go for your app, but note that the contrib module is currently only in master, not an official release. The master branch is well tested but if you're already running an official release (e.g. 1.4.3) in production you may prefer to use https://github.com/rkhleics/wagtailmodeladmin until Wagtail 1.5 is released, probably in early May.

Good luck with your project!

Tom
Reply all
Reply to author
Forward
0 new messages