1

I have a SnippetViewSet in Wagtail 5 which is in fact a boolean. The field is added in the queryset using an annotation:

class PartnerViewSet(SnippetViewSet):
    model = Partner

    list_display = [
        Column("is_current_partner", label=_("Current partner"), accessor="is_current_partner")
    ]

    def get_queryset(self, request):
        return (
            Partner.objects.all()
            # To check whether the partner is a current partner or not
            .annotate(
                is_current_partner=Exists(
                    EditionPartnership.objects.filter(
                        edition__is_current=True,
                        partner_id=OuterRef("pk"),
                    )
                )
            )
        )

However in Wagtail admin, this displays as either "True" or as an empty value if False. Ideally this would be a checkbox or something similar to Django Admin.

Is this possible out of the box?

Maarten Ureel
  • 393
  • 4
  • 18

2 Answers2

1

Looking at the source for the Column class, you might be able to create a subclass of Column with its own render_cell_html to display this boolean as a checkbox. But that sort of display might be confusing unless you also customized it to do something if you checked or unchecked the box while in the list view.

cnk
  • 981
  • 1
  • 5
  • 9
0

Based on the response from cnk, I ended up with this by overriding the get_value() method:

class BooleanColumn(Column):
    def get_value(self, instance):
        value = super().get_value(instance)

        return "✅" if value else "⛔"

That way no changes to the template etc are needed.

Maarten Ureel
  • 393
  • 4
  • 18