Skip to content

Commit

Permalink
fix: Solve circular imports in models
Browse files Browse the repository at this point in the history
- move call to get_user_model from a module level to function level in utils.
- use settings.AUTH_USER_MODEL in models.
  • Loading branch information
TSolo315 authored and abhiabhi94 committed Mar 10, 2021
1 parent 1f5c443 commit fbee6fa
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 6 deletions.
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

0 comments on commit fbee6fa

Please sign in to comment.