I have one class (DeckDeviceUtil
) with an abstract function (get_active_deckdevices
) who needs to be inherited by 2 classes (Deck and Device). The structure is as follows:
A.py
from models import Deck
class DeckDeviceUtil:
@property
@abstractmethod
def deckdevice(self):
pass
def get_active_deckdevices(self):
#somecode
class Device(models.Model, DeckDeviceUtil):
#somecode
class DeckDevice(models.Model):
#uses Deck
B.py
from backend.devices.models import DeckDeviceUtil
class Deck(models.Model, DeckDeviceUtil):
#somecode
I get following error:
from backend.house.models import Deck
ImportError: cannot import name 'Deck'
probably because the 2 python files/classes need each other. When I try to do the imports inside the classes there are other errors
when import DeckDeviceUtil inside Deck :
class Deck(models.Model, DeckDeviceUtil):
NameError: name 'DeckDeviceUtil' is not defined
when import Deck inside Device:
from backend.house.models import Deck
ImportError: cannot import name 'Deck'
Important: Device needs to import Deck
What's the best way to solve this?