Opened 2 years ago
Closed 2 years ago
#33923 closed New feature (duplicate)
Swappable Model support for Group Model
Reported by: | Vasanth | Owned by: | nobody |
---|---|---|---|
Component: | contrib.auth | Version: | 4.1 |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
When dealing with custom groups there are two ways of extending the model
- Create a separate "GroupExtension" model and define an OneToOne relationship to the Group model
- Inherit the default Group Model into a new CustomGroup model
Since my current project uses object-level permission (django-guardian) everywhere and quite a few additional fields I decided to go along with option 2. However, I quickly found that the Group model is not swappable in the same manner as the user model.
Trying to implement it manually has further let me down the rabbit hole where I found that libraries have hardcoded dependency onto the Group model directly. This makes working with custom group models quite hard.
It'd be great if the the group model can also be defined in the settings which can then be leveraged by all libraries to provide a smoother dev experience working with Custom Group and permissions
For reference my current user and group looks something like,
class CustomGroup(Group): additional_field = models.CharField(max_length=10) .... class CustomUser(AbstractBaseUser, PermissionsMixin): groups = models.ManyToManyField(CustomGroup) ....
Duplicate of #29748.