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
| Attribute | Type | Description |
|---|---|---|
| search_fields | tuple = ("name",) | List of fields used to build the search query in the admin interface, enabling keyword filtering by group name. |
| ordering | tuple = ("name",) | Specifies the default sort order for group records displayed in the admin change list view. |
| filter_horizontal | tuple = ("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
| Name | Type | Description |
|---|---|---|
| db_field | django.db.models.Field | The database field object being converted into a form field. |
| request | django.http.HttpRequest | The current HTTP request object from the admin interface. |
| **kwargs | dict | Additional keyword arguments used to initialize the form field. |
Returns
| Type | Description |
|---|---|
django.forms.Field | A form field instance with an optimized queryset for permissions that includes related content type data. |