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

Avoid circular import issues. #18

Merged
merged 1 commit into from
Mar 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions flag/models.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from collections import namedtuple
from enum import IntEnum, unique

from django.contrib.auth import get_user_model
from django.contrib.contenttypes.fields import GenericForeignKey
from django.contrib.contenttypes.models import ContentType
from django.core.exceptions import ValidationError
Expand All @@ -12,7 +11,7 @@
from flag.managers import FlagInstanceManager, FlagManager
from flag.conf import settings

User = get_user_model()
User = settings.AUTH_USER_MODEL


class Flag(models.Model):
Expand Down
6 changes: 2 additions & 4 deletions flag/utils.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
"""General purpose functions that provide utility throughout the application"""
from django.contrib.auth import get_user_model
from django.apps import apps
from django.contrib.contenttypes.models import ContentType
from django.contrib.auth import get_user_model
from django.core.exceptions import ValidationError
from django.utils.translation import gettext_lazy as _


User = get_user_model()


def get_content_type(model_obj):
return ContentType.objects.get_for_model(model_obj.__class__)

Expand All @@ -31,6 +28,7 @@ def get_model_object(*, app_name, model_name, model_id):


def get_user_for_model(obj):
User = get_user_model()
for field in obj._meta.fields:
if field.related_model == User:
return getattr(obj, field.name)
Expand Down