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

Using user foreign key to settings.AUTH_USER_MODEL instead of "username" in User_Keys #77

Open
oussjarrousse opened this issue Dec 22, 2023 · 0 comments

Comments

@oussjarrousse
Copy link

Currently the User_Keys model in models.py, uses username=models.CharField(max_length = 50).

This could be problematic in case the django app allows for changing the username for example. Also deleting a user will not result in deleting entries for that user in the User_Keys model in the database.

The mainstream approach is to use:

user = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE)

The request in django view functions already have request.user variable that can be used directly when CRUD an entry in the User_Keys table.

Nonetheless, changing the data model will require a lot of refactoring.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant