无法导入其他应用的模型表单模型

时间:2021-04-01 16:31:25

标签: django django-models

这是transaction.model的代码 在这里,我试图从 WalletUser.models 导入 WalletUser 模型

import uuid as uuid
from django.db import models
from walletApp.WalletUser.models import WalletUser

class Transaction(models.Model):
STATUS_TYPES = (
    ('C', 'Compleat'),
    ('S', 'Success'),
    ('I', 'Incompleat'),
    ('A', 'aborted'),
)
uuid = models.UUIDField(unique=True, default=uuid.uuid4, editable=False, db_index=True)
status = models.CharField(choices=STATUS_TYPES, default='N', max_length=3)
created_on = models.DateTimeField(auto_now_add=True, null=False)
user = models.ForeignKey(WalletUser)
amount = models.FloatField()

def __str__(self):
    return self.uuid

我收到此错误

/Users/shoaib/Documents/walletTransactionSystem/walletApp/walletApp/settings.py changed, 
reloading.
Watching for file changes with StatReloader
Exception in thread django-main-thread:
Traceback (most recent call last):
  File             "/usr/local/Cellar/python/3.7.7/Frameworks/Python.framework/Versions/3.7/lib/python3.7/threading.py", line 926, in _bootstrap_inner
self.run()
  File     "/usr/local/Cellar/python/3.7.7/Frameworks/Python.framework/Versions/3.7/lib/python3.7/threading.py", line 870, in run
self._target(*self._args, **self._kwargs)
  File "/Users/shoaib/Documents/walletTransactionSystem/venv/lib/python3.7/site-packages/django/utils/autoreload.py", line 53, in wrapper
fn(*args, **kwargs)
  File "/Users/shoaib/Documents/walletTransactionSystem/venv/lib/python3.7/site-packages/django/core/management/commands/runserver.py", line 110, in inner_run
autoreload.raise_last_exception()
  File "/Users/shoaib/Documents/walletTransactionSystem/venv/lib/python3.7/site-packages/django/utils/autoreload.py", line 76, in raise_last_exception
raise _exception[1]
  File "/Users/shoaib/Documents/walletTransactionSystem/venv/lib/python3.7/site-packages/django/core/management/__init__.py", line 357, in execute
autoreload.check_errors(django.setup)()
  File "/Users/shoaib/Documents/walletTransactionSystem/venv/lib/python3.7/site-packages/django/utils/autoreload.py", line 53, in wrapper
fn(*args, **kwargs)
  File "/Users/shoaib/Documents/walletTransactionSystem/venv/lib/python3.7/site-packages/django/__init__.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
  File "/Users/shoaib/Documents/walletTransactionSystem/venv/lib/python3.7/site-packages/django/apps/registry.py", line 114, in populate
app_config.import_models()
  File "/Users/shoaib/Documents/walletTransactionSystem/venv/lib/python3.7/site-packages/django/apps/config.py", line 211, in import_models
self.models_module = import_module(models_module_name)
  File "/usr/local/Cellar/python/3.7.7/Frameworks/Python.framework/Versions/3.7/lib/python3.7/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
  File "<frozen importlib._bootstrap>", line 983, in _find_and_load
  File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 728, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/Users/shoaib/Documents/walletTransactionSystem/walletApp/transaction/models.py", line 4, in <module>
    from walletApp.WalletUser.models import WalletUser
ModuleNotFoundError: No module named 'walletApp.WalletUser'

我也尝试过 walletApp.WalletUser.models 和 WalletUser.models 都不起作用。 WalletUser.models 是直接捐赠。 PLZ帮助我卡住了

1 个答案:

答案 0 :(得分:0)

from WalletUser.models import WalletUser

你们很亲近!由于您的应用与基础目录在同一目录中,因此您无需指定基础目录,您只需从应用中导入模型即可。

相关问题