I am creating an application for teaching management in Wagtail. I create an AdminModal for 'Subjects'. I want to allow only selected user group to access a selected subject. Just like "Page permissions" in 'Add group'. Any idea how to do that?
2 Answers
You can do this by overriding get_queryset
method in the ModelAdmin
class that is associated with the Subject
model.
def get_queryset(self, request):
qs = super().get_queryset(request)
valid_subjects = ['subject1', 'subject2', 'subject3']
return qs.filter(subject_name__in=valid_subjects)
The above example shows a way to restrict users from subject name. If you need to access group, you need to have a relation between Subject
model and Group
model. Then all you have to do is change the filter query.
You can find more about querying in this documentation.

- 4,853
- 6
- 46
- 67
First, I am assuming when you say AdminModal, you actually mean a ModelAdmin model for subjects. If that is not the case, can you please show me where AdminModal comes from?
The subject will need a field you can use to identify which group should be able to manage it. Then you will need to customize the admin interface for your Subjects model. In particular you will need to enforce some permissions - and create some custom get_queryset
methods so users are only shown Subjects they should be able to edit. Start with this part of the documentation and post back when you have more specific questions: https://docs.wagtail.org/en/stable/reference/contrib/modeladmin/primer.html

- 981
- 1
- 5
- 9