Customizing authentication e autorization, with constant for models names User, Permission, Group, PermissionMixin and constant for field names and table name

69 views
Skip to first unread message

Jansen Magalhães

unread,
Feb 15, 2023, 10:12:40 AM2/15/23
to Django developers (Contributions to Django itself)
Dear, 

I would like to debate the possibility of updating Django regarding a better customization of the Auth app, with the possibility of customizing the models, field names, table names, through constants to be defined throughout the application for the actions of the models User, Permission, Group, PermissionMixin.

Adam Johnson

unread,
Feb 15, 2023, 12:06:20 PM2/15/23
to django-d...@googlegroups.com
Hi Jansen,

I would like to see a more concrete and thought-out proposal, with the motivation. For many problems you might encounter with the auth module, there is a way to customize it. Beyond a certain point though, “reimplement it yourself” is a reasonable solution. For example, if you need a different database table name for Group, I’d say that would be grounds to implement your own Group model - which really isn’t much code.

Thanks,

Adam



Jansen Magalhães

unread,
Feb 15, 2023, 2:18:22 PM2/15/23
to Django developers (Contributions to Django itself)
Hi Adam, 

Thanks for the feedback! 

I tried to leverage app auth framework to customize User, Permission, Group, PermissionMixin models. 

As for the User it works normally. There is the possibility to extend the models and place the db_table in the User Meta. There is also a constant AUTH_USER_MODEL to identify the CustomUser model that will be used for authentication. There are also the constant USERNAME_FIELD, EMAIL_FIELD to identify the model fields. 

The documentation also contains guidance on the AUTHENTICATION_BACKENDS constant to customize the authentication rules. 

I suggest the possibility of thinking about having similar constants for the Permission, Group, PermissionMixin models for a next update. 

For example, for the Pemisson model we can access it alternatively through an identification of a constant AUTH_PERMISSION_MODEL. The rest likewise AUTH_GROUP_MODEL, AUTH_USER_PERMISSIONS_MODEL, AUTH_USER_GROUPS_MODEL, AUTH_GROUP_PERMISSION_MODEL. 

It could also have the possibility of constants to identify the name of the fields in each of these models of the Auth app. For Permission would have: NAME, CODENAME. For Group it would have: NAME.

Respectfully,

Jansen

Reply all
Reply to author
Forward
0 new messages