Python 3.8
models.py
from gettext import gettext
import omnibus.model_mixins.general as general
from django.db import models
import model_mixins
class Client(general.NameMixin,
general.FlagMixin,
model_mixins.DirMixin,
general.ArchivedMixin,
general.CommentMixin,
models.Model):
class Meta:
verbose_name = gettext("Client")
verbose_name_plural = gettext("Clients")
model_mixins.py
from django.db import models
from django.db.models import Index
from django.utils.translation import gettext
class DirMixin:
dir = models.CharField(max_length=30,
unique=True,
verbose_name=gettext("Target directory"))
class Meta:
abstract = True
Index(fields=['dir', ])
树
├── ads6
│ ├── asgi.py
│ ├── __init__.py
│ ├── __pycache__
│ │ ├── __init__.cpython-38.pyc
│ │ ├── settings.cpython-38.pyc
│ │ └── urls.cpython-38.pyc
│ ├── settings.py
│ ├── urls.py
│ └── wsgi.py
├── clients
│ ├── admin.py
│ ├── apps.py
│ ├── __init__.py
│ ├── migrations
│ │ └── __init__.py
│ ├── model_mixins.py
│ ├── models.py
│ ├── __pycache__
│ │ ├── __init__.cpython-38.pyc
│ │ └── models.cpython-38.pyc
│ ├── tests.py
│ └── views.py
├── db.sqlite3
**migrations**
(venv) michael@michael:~/PycharmProjects/ads6/ads6$ python manage.py makemigrations
Traceback (most recent call last):
File "manage.py", line 22, in <module>
main()
File "manage.py", line 18, in main
execute_from_command_line(sys.argv)
File "/home/michael/PycharmProjects/ads6/venv/lib/python3.8/site-packages/django/core/management/__init__.py", line 401, in execute_from_command_line
utility.execute()
File "/home/michael/PycharmProjects/ads6/venv/lib/python3.8/site-packages/django/core/management/__init__.py", line 377, in execute
django.setup()
File "/home/michael/PycharmProjects/ads6/venv/lib/python3.8/site-packages/django/__init__.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File "/home/michael/PycharmProjects/ads6/venv/lib/python3.8/site-packages/django/apps/registry.py", line 114, in populate
app_config.import_models()
File "/home/michael/PycharmProjects/ads6/venv/lib/python3.8/site-packages/django/apps/config.py", line 211, in import_models
self.models_module = import_module(models_module_name)
File "/usr/lib/python3.8/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
File "<frozen importlib._bootstrap>", line 991, in _find_and_load
File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 783, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/home/michael/PycharmProjects/ads6/ads6/clients/models.py", line 6, in <module>
import model_mixins
ModuleNotFoundError: No module named 'model_mixins'
(venv) michael@michael:~/PycharmProjects/ads6/ads6$
你能帮我解决这个问题吗?我不想使用“从进口”。我想坚持“导入model_mixins”。
答案 0 :(得分:0)
真正使用它:-
from .model_mixins import DirMixin
而不是:-
from . import model_mixins