Skip to main content

GroupAdmin

This class provides a customized administrative interface for managing user groups and their associated permissions. It configures search and ordering capabilities based on group names and implements a horizontal filter for permission selection. Additionally, it optimizes performance by pre-fetching related content types when loading the many-to-many permission field.

Attributes

AttributeTypeDescription
search_fieldstuple = ("name",)List of fields used to build the search query in the admin interface, enabling keyword filtering by group name.
orderingtuple = ("name",)Specifies the default sort order for group records displayed in the admin change list view.
filter_horizontaltuple = ("permissions",)Enables a JavaScript-based interface for selecting permissions, allowing users to move items between 'Available' and 'Chosen' columns.

Methods


formfield_for_manytomany()

@classmethod
def formfield_for_manytomany(
db_field: django.db.models.Field,
request: django.http.HttpRequest,
**kwargs: dict
) - > django.forms.Field

Customizes the ManyToMany form field for the Group model, specifically optimizing the permissions field to prevent performance bottlenecks.

Parameters

NameTypeDescription
db_fielddjango.db.models.FieldThe database field object being converted into a form field.
requestdjango.http.HttpRequestThe current HTTP request object from the admin interface.
**kwargsdictAdditional keyword arguments used to initialize the form field.

Returns

TypeDescription
django.forms.FieldA form field instance with an optimized queryset for permissions that includes related content type data.