I am attempting to import a model from a sibling package and am getting
ValueError: attempted relative import beyond top-level package
Strangely, I am auto-filling based on PyCharm suggestions, so the IDE is registering the module, but my build is failing...
]1
Here is my project structure:
app
\
+-core
| \
| +- __init__.py
| +- models.py <- the Tag model is present here
|
+-scheduler
| \
| +- __init__.py
| +- serializers.py <- importing app.core.models.Tag in this file
|
+- __init__.py
app.scheduler.serializers.py:
from rest_framework import serializers
from ..core.models import Tag
class TagSerializer(serializers.ModelSerializer):
"""Serializer for tag objects"""
class Meta:
model = Tag
fields = ('id', 'name')
read_only_fields = ('id',)
I've been scratching my head about this and can't seem to figure it out...
I've tried using an absolute path, even adding it using the PyCharm import utility:
from rest_framework import serializers
from app.core.models import Tag
class TagSerializer(serializers.ModelSerializer):
"""Serializer for tag objects"""
class Meta:
model = Tag
fields = ('id', 'name')
read_only_fields = ('id',)
but then I get:
ModuleNotFoundError: No module named 'app.core'
I am running using
python manage.py runserver