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

Add organization and team models #2071

Closed

Conversation

cutwater
Copy link
Contributor

@cutwater cutwater commented Feb 15, 2024

  • 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

@github-actions github-actions bot added backport-4.2 This PR should be backported to stable-4.2 (1.2) backport-4.4 This PR should be backported to stable-4.4 (2.1) backport-4.5 This PR should be backported to stable-4.5 (2.2) backport-4.6 This PR should be backported to stable-4.6 (2.3) backport-4.7 This PR should be backported to stable-4.7 (2.4) backport-4.8 This PR should be backported to stable-4.8 (2.4) backport-4.9 This PR should be backported to stable-4.9 (2.4) labels Feb 15, 2024
"""A team model."""

users = models.ManyToManyField(
settings.AUTH_USER_MODEL,
Copy link
Member

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.

Copy link
Contributor Author

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 use models.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(...)

@cutwater cutwater force-pushed the feature/AAP-20256-org-model branch 3 times, most recently from b6d5394 to c4fa6c7 Compare February 16, 2024 15:14
* 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
@cutwater cutwater force-pushed the feature/AAP-20256-org-model branch from c4fa6c7 to eaa6dc9 Compare March 4, 2024 12:25
@newswangerd newswangerd removed backport-4.2 This PR should be backported to stable-4.2 (1.2) backport-4.4 This PR should be backported to stable-4.4 (2.1) backport-4.5 This PR should be backported to stable-4.5 (2.2) backport-4.6 This PR should be backported to stable-4.6 (2.3) backport-4.7 This PR should be backported to stable-4.7 (2.4) backport-4.8 This PR should be backported to stable-4.8 (2.4) backport-4.9 This PR should be backported to stable-4.9 (2.4) labels Mar 5, 2024
@cutwater cutwater closed this Mar 12, 2024
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

Successfully merging this pull request may close these issues.

2 participants