Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove add site/user from Role admin (#943) #1014

Merged
merged 2 commits into from
Jun 6, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions rdmo/accounts/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,24 @@ class RoleAdmin(admin.ModelAdmin):

list_display = ('user', 'email', 'members', 'managers', 'editors', 'reviewers')

readonly_fields = ('user', )

def get_queryset(self, request):
return Role.objects.prefetch_related(
'member', 'manager', 'editor', 'reviewer').annotate(
Count('member'), Count('manager'), Count('editor'), Count('reviewer'),
sites_count=Value(Site.objects.count())
)

def get_form(self, request, obj=None, **kwargs):
form = super().get_form(request, obj, **kwargs)
form.base_fields['member'].widget.can_add_related = False
form.base_fields['manager'].widget.can_add_related = False
form.base_fields['editor'].widget.can_add_related = False
form.base_fields['reviewer'].widget.can_add_related = False

return form

@staticmethod
def render_all_sites_or_join(obj, field_name: str) -> str:
if getattr(obj, f'{field_name}__count', 0) == obj.sites_count:
Expand Down
Loading