-
Notifications
You must be signed in to change notification settings - Fork 133
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
Add organization and team models #2071
Conversation
dbec270
to
00650a7
Compare
"""A team model.""" | ||
|
||
users = models.ManyToManyField( | ||
settings.AUTH_USER_MODEL, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd recommend using the get_user_model()
function that django provides for this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think it's the case here and actually Django documentation explicitly states to use settings.AUTH_USER_MODEL
in foreign keys.
https://docs.djangoproject.com/en/5.0/topics/auth/customizing/
When you define a foreign key or many-to-many relations to the user model, you should specify the custom model using the AUTH_USER_MODEL setting.
However there is vague statement, that get_user_model
may be used instead, though it is not obvious which benefits it gives in this specific case.
Generally speaking, it’s easiest to refer to the user model with the AUTH_USER_MODEL setting in code that’s executed at import time, however, it’s also possible to call
get_user_model()
while Django is importing models, so you could usemodels.ForeignKey(get_user_model(), ...)
.
The get_user_model()
function call is useful where you need to use a model instance, not a string. For instance to make a query:
User = get_user_model()
User.objects.get(...)
b6d5394
to
c4fa6c7
Compare
* Add new `Oranization` and `Team` models, that implement respective abstract models from DAB. * Add related database migrations and data migration, that creates a new default model. * Implement custom manager for the `Organization` model that retrieves the default organization. No-Issue
c4fa6c7
to
eaa6dc9
Compare
Oranization
andTeam
models, that implement respective abstract models from DAB.Organization
model that retrieves the default organization.No-Issue