paubins
paubins

Reputation: 151

Importing a model in Django that shares it's name between two different applications problem

I have two apps one named "challenge" another named "stats"; within the models.py files of both I have classes named Team. They serve two complete seperate purposes. When I import from another app

from stats.models import Team

it will only and always import the Team model from challenge, rather than from stats. If I import from challenge

from challenge.models import Team

it will import correctly from challenge. When I use the shell I get the following:

>>> from stats.models import Team
>>> Team
<class 'challenge.models.Team'>

I thought it may have been within the order of applications in INSTALLED_APPS within the settings.py so I rearranged them to no avail.

Is there some weird circular dependency thing I'm not catching or is this a bug within Django? What's going on?

Upvotes: 0

Views: 75

Answers (1)

fceruti
fceruti

Reputation: 2445

how about:

from challenge.models import Team as ChallengeTeam
from stats.models import Team as StatsTeam

ChallengeTeam
>>> <class 'challenge.models.Team'>

StatsTeam
>>> <class 'stats.models.Team'>

Upvotes: 1

Related Questions