I want to limit the number of the users displayed in the ManyToManyField in the Wagtail admin.
In the django version of the ModelAdmin it was enough to implement the following:
def partner_users_queryset(queryset, field, request):
user = request.user
if queryset and field == "users":
return queryset.filter(groups__pk__in=user.groups.all())
return queryset
@django_admin.register(Partner)
class PartnerAdmin(django_admin.ModelAdmin):
...
def get_field_queryset(self, db, db_field, request):
queryset = super().get_field_queryset(db, db_field, request)
return partner_users_queryset(queryset, db_field.name, request)
Is there a way in the Wagtail to limit what values are shown in the ManyToManyFields?
It seems currently there's no straightforward way to do the same in the
wagtail. Somewhat equivalent code would look like the following: