This is the models.py file. Although you can see that i have used MEDIA_URL as the directory for the image to be saved, i have also messed around with all other alternatives getting similar error messages. Could this have something to do with permissions? im not sure.
from django.db import models
from taggit.managers import TaggableManager
class Post(models.Model):
title = models.CharField(max_length = 100)
body = models.TextField()
created = models.DateTimeField()
image1 = models.ImageField(upload_to = MEDIA_URL)
def __unicode__(self):
return self.title
This is the settings part i have added.
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
MEDIA_URL = '/media/'
And this is the error message i am getting in the cmd(using windows)
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "C:\Python34\lib\site-packages\django\core\management\__init__.py", line 399, in execute_from_command_line
utility.execute()
File "C:\Python34\lib\site-packages\django\core\management\__init__.py", line 392, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\Python34\lib\site-packages\django\core\management\base.py", line 242, in run_from_argv
self.execute(*args, **options.__dict__)
File "C:\Python34\lib\site-packages\django\core\management\base.py", line 284, in execute
self.validate()
File "C:\Python34\lib\site-packages\django\core\management\base.py", line 310, in validate
num_errors = get_validation_errors(s, app)
File "C:\Python34\lib\site-packages\django\core\management\validation.py", line 34, in get_validation_errors
for (app_name, error) in get_app_errors().items():
File "C:\Python34\lib\site-packages\django\db\models\loading.py", line 196, in get_app_errors
self._populate()
File "C:\Python34\lib\site-packages\django\db\models\loading.py", line 75, in _populate
self.load_app(app_name, True)
File "C:\Python34\lib\site-packages\django\db\models\loading.py", line 99, in load_app
models = import_module('%s.models' % app_name)
File "C:\Python34\lib\importlib\__init__.py", line 109, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 2254, in _gcd_import
File "<frozen importlib._bootstrap>", line 2237, in _find_and_load
File "<frozen importlib._bootstrap>", line 2226, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 1200, in _load_unlocked
File "<frozen importlib._bootstrap>", line 1129, in _exec
File "<frozen importlib._bootstrap>", line 1471, in exec_module
File "<frozen importlib._bootstrap>", line 321, in _call_with_frames_removed
File "C:\Users\Neema\sonder\blog\models.py", line 4, in <module>
class Post(models.Model):
File "C:\Users\Neema\sonder\blog\models.py", line 8, in Post
image1 = models.ImageField(upload_to = MEDIA_URL)
NameError: name 'MEDIA_URL' is not defined
I think you need to add a import to your models.py:
from django.conf import settings
And then you can use it:
settings.MEDIA_URL
Anyway, I don't think it is a good practice to add the MEDIA_URL to your field. If in the future you decide to change it, you need to update all the DB entries.
Don't mention MEDIA_URL in your models.py at all. Just mention a subdirectory name. For e.g.
image1 = models.ImageField(upload_to="blogimages")
Make sure that the media folder has write access by server (Apache or IIS). This is a common problem in Windows. It can be fixed easily by right clicking the folder and changing the permissions.
If you still get an error, please post that as well.
Related
I have a set of models:
class DebugConf(models.Model):
is_setup = models.BooleanField(default=False)
debug_setup_date = models.DateTimeField()
def __str__(self):
return self.is_setup
class Currency(models.Model):
currency_name = models.CharField(max_length=100)
currency_value_in_dollars = models.FloatField()
currency_value_in_dollars_date = models.DateTimeField()
def __str__(self):
return self.currency_name
class User(models.Model):
user_name = models.CharField(max_length=200)
user_pass = models.CharField(max_length=200)
join_date = models.DateTimeField()
def __str__(self):
return self.user_name
class Transaction(models.Model):
transaction_type = models.CharField(max_length=200)
transaction_amount = models.FloatField()
transaction_date = models.DateTimeField()
transaction_currency = models.ForeignKey(Currency, on_delete=models.CASCADE)
transaction_users = models.ForeignKey(User, on_delete=models.CASCADE)
def __str__(self):
return self.headline
a project 'crypto' and an app 'manage_crypto_currency' nested into it:
The app's views contains some initialization code:
views.py:
if IS_DEBUG_MODE:
print('[!!!INFO!!!] DEBUG MODE SET! USING GENERATED TABLES')
init_debug_tables()
def init_debug_tables():
# Check if debug table has already been initialized
debug_conf = DebugConf.objects.all()
if debug_conf.objects.exists():
return
At the moment, the db is not initialized; when running:
python manage.py makemigrations manage_crypto_currency
in the root (project dir):
I get:
[!!!INFO!!!] DEBUG MODE SET! USING GENERATED TABLES
Traceback (most recent call last):
File "manage.py", line 24, in <module>
main()
File "manage.py", line 20, in main
execute_from_command_line(sys.argv)
File "C:\projects\django\crypto-currency-board\venv\lib\site-packages\django\core\management\__init__.py", line 401, in execute_from_command_line
utility.execute()
File "C:\projects\django\crypto-currency-board\venv\lib\site-packages\django\core\management\__init__.py", line 395, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\projects\django\crypto-currency-board\venv\lib\site-packages\django\core\management\base.py", line 330, in run_from_argv
self.execute(*args, **cmd_options)
File "C:\projects\django\crypto-currency-board\venv\lib\site-packages\django\core\management\base.py", line 368, in execute
self.check()
File "C:\projects\django\crypto-currency-board\venv\lib\site-packages\django\core\management\base.py", line 392, in check
all_issues = checks.run_checks(
File "C:\projects\django\crypto-currency-board\venv\lib\site-packages\django\core\checks\registry.py", line 70, in run_checks
new_errors = check(app_configs=app_configs, databases=databases)
File "C:\projects\django\crypto-currency-board\venv\lib\site-packages\django\core\checks\urls.py", line 13, in check_url_config
return check_resolver(resolver)
File "C:\projects\django\crypto-currency-board\venv\lib\site-packages\django\core\checks\urls.py", line 23, in check_resolver
return check_method()
File "C:\projects\django\crypto-currency-board\venv\lib\site-packages\django\urls\resolvers.py", line 408, in check
for pattern in self.url_patterns:
File "C:\projects\django\crypto-currency-board\venv\lib\site-packages\django\utils\functional.py", line 48, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "C:\projects\django\crypto-currency-board\venv\lib\site-packages\django\urls\resolvers.py", line 589, in url_patterns
patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
File "C:\projects\django\crypto-currency-board\venv\lib\site-packages\django\utils\functional.py", line 48, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "C:\projects\django\crypto-currency-board\venv\lib\site-packages\django\urls\resolvers.py", line 582, in urlconf_module
return import_module(self.urlconf_name)
File "C:\Users\msebi\AppData\Local\Programs\Python\Python38-32\lib\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 "C:\projects\django\crypto-currency-board\crypto\crypto\urls.py", line 21, in <module>
path('', include('manage_crypto_currency.urls')),
File "C:\projects\django\crypto-currency-board\venv\lib\site-packages\django\urls\conf.py", line 34, in include
urlconf_module = import_module(urlconf_module)
File "C:\Users\msebi\AppData\Local\Programs\Python\Python38-32\lib\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 "C:\projects\django\crypto-currency-board\crypto\manage_crypto_currency\urls.py", line 5, in <module>
from . import views
File "C:\projects\django\crypto-currency-board\crypto\manage_crypto_currency\views.py", line 24, in <module>
init_debug_tables()
File "C:\projects\django\crypto-currency-board\crypto\manage_crypto_currency\setup_test_db\setup_debug_tables.py", line 14, in init_debug_tables
if debug_conf.objects.exists():
AttributeError: 'QuerySet' object has no attribute 'objects'
The line:
[!!!INFO!!!] DEBUG MODE SET! USING GENERATED TABLES
is in views. Apparently, the migrations tool feels the need to execute views.py. Why on Earth, I have no clue. Is it possible to make makemigrations NOT execute code that it shouldn't, e.g. just create the models given that the db is not initialized?
EDIT
The answers don't answer WHY migrate runs views.py (I don't know either), but commenting out:
# if IS_DEBUG_MODE:
# print('[!!!INFO!!!] DEBUG MODE SET! USING GENERATED TABLES')
# init_debug_tables()
leads to successful migration. Is there a less cumbersome way to go about it? (Un)comment is ugly.
You don't need to use call the objects of a QuerySet
def init_debug_tables():
# Check if debug table has already been initialized
debug_conf = DebugConf.objects.all()
if debug_conf.exists(): # instead of `debug_conf.objects.exists()`
return
As the error message suggest, debug_conf is the the model class, it is an instance of a QuerySet.
objects is the Manager attached to a model class. This managers creates QuerySet for you (in your code, by the return value of the all method).
So you want to do this:
def init_debug_tables():
# Check if debug table has already been initialized
debug_conf = DebugConf.objects.all()
if debug_conf.exists():
return
I'm trying to make a model that needs a relationship of one to one with a feedstock that is used by a plenty of formulas. This is my code:
from django.db import models
from dashboard.models import Formulas, Feedstock
class FeedstockFormulas(models.Model):
ratio = models.FloatField()
feedstock = models.OneToOneField(Feedstock, on_delete=models.CASCADE, default="0")
formulas = models.ForeignKey(Formulas, on_delete=models.CASCADE)
This is the error I'm getting:
Traceback (most recent call last):
File "/home/isaacrpl7/.local/lib/python3.8/site-packages/django/db/models/fields/related.py", line 798, in __init__
to._meta.model_name
AttributeError: module 'dashboard.models.Feedstock' has no attribute '_meta'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "manage.py", line 22, in <module>
execute_from_command_line(sys.argv)
File "/home/isaacrpl7/.local/lib/python3.8/site-packages/django/core/management/__init__.py", line 401, in execute_from_command_line
utility.execute()
File "/home/isaacrpl7/.local/lib/python3.8/site-packages/django/core/management/__init__.py", line 377, in execute
django.setup()
File "/home/isaacrpl7/.local/lib/python3.8/site-packages/django/__init__.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File "/home/isaacrpl7/.local/lib/python3.8/site-packages/django/apps/registry.py", line 114, in populate
app_config.import_models()
File "/home/isaacrpl7/.local/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 "/mnt/c/Users/isaac/Documents/Github/uniaoracoes/dashboard/models/__init__.py", line 1, in <module>
from .Formulas import Formulas
File "/mnt/c/Users/isaac/Documents/Github/uniaoracoes/dashboard/models/Formulas.py", line 2, in <module>
from dashboard.models import FeedstockFormulas
File "/mnt/c/Users/isaac/Documents/Github/uniaoracoes/dashboard/models/FeedstockFormulas.py", line 4, in <module>
class FeedstockFormulas(models.Model):
File "/mnt/c/Users/isaac/Documents/Github/uniaoracoes/dashboard/models/FeedstockFormulas.py", line 6, in FeedstockFormulas
feedstock = models.OneToOneField(Feedstock, on_delete=models.CASCADE, default="0")
File "/home/isaacrpl7/.local/lib/python3.8/site-packages/django/db/models/fields/related.py", line 1049, in __init__
super().__init__(to, on_delete, to_field=to_field, **kwargs)
File "/home/isaacrpl7/.local/lib/python3.8/site-packages/django/db/models/fields/related.py", line 800, in __init__
assert isinstance(to, str), (
AssertionError: OneToOneField(<module 'dashboard.models.Feedstock' from '/mnt/c/Users/isaac/Documents/Github/uniaoracoes/dashboard/models/Feedstock.py'>) is invalid. First parameter to ForeignKey must be either a model, a model name, or the string 'self'
I can't really solve it, since the first parameter to ForeignKey is already a model...
It looks like this is a by-product of a circular import somewhere.
Try changing to
feedstock = models.OneToOneField("dashboard.Feedstock", on_delete=models.CASCADE, default="0")
formulas = models.ForeignKey("dashboard.Formulas", on_delete=models.CASCADE)
I'm new to django and I'm trying to extend the user class in one of my apps but I'm having trouble redirecting from setting.py to the model that contains my AbstractUser
My Nproject:
-apps:
--profile:
---__init__.py
---apps.py
---forms.py
---models.py
---urls.py
---views.py
--apps1
-media
-static
-templates
-Nproject:
--__init__.py
--settings.py
--urls.py
--wsgi.py
model in apps.profile.models
from django.db import models
from django.contrib.auth.models import AbstractUser
class User(AbstractUser):
address = models.CharField(max_length=255)
def __str__(self):
return '%s %s' % (self.email, self.username)
setting.py and here I think this is my mistake
AUTH_USER_MODEL = 'apps.User' #not working
I think the error is in AUTH_USER_MODEL that I do not know how to properly reference the model User
Research some sites and tell me that you should use the init.py file but it is not working
init in apps.profile
from .models import User
Error:
Traceback (most recent call last):
File "./manage.py", line 22, in <module>
execute_from_command_line(sys.argv)
File "/home/projects/.virtualenvs/Nproject/lib/python3.6/site-packages/django/core/management/__init__.py", line 371, in execute_from_command_line
utility.execute()
File "/home/projects/.virtualenvs/Nproject/lib/python3.6/site-packages/django/core/management/__init__.py", line 347, in execute
django.setup()
File "/home/projects/.virtualenvs/Nproject/lib/python3.6/site-packages/django/__init__.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File "/home/projects/.virtualenvs/Nproject/lib/python3.6/site-packages/django/apps/registry.py", line 89, in populate
app_config = AppConfig.create(entry)
File "/home/projects/.virtualenvs/Nproject/lib/python3.6/site-packages/django/apps/config.py", line 90, in create
module = import_module(entry)
File "/home/projects/.virtualenvs/Nproject/lib/python3.6/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 978, in _gcd_import
File "<frozen importlib._bootstrap>", line 961, in _find_and_load
File "<frozen importlib._bootstrap>", line 950, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 655, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 678, in exec_module
File "<frozen importlib._bootstrap>", line 205, in _call_with_frames_removed
File "/home/projects/Nproject/apps/perfil/__init__.py", line 1, in <module>
from .models import User
File "/home/projects/Nproject/apps/perfil/models.py", line 2, in <module>
from django.contrib.auth.models import User
File "/home/projects/.virtualenvs/Nproject/lib/python3.6/site-packages/django/contrib/auth/models.py", line 2, in <module>
from django.contrib.auth.base_user import AbstractBaseUser, BaseUserManager
File "/home/projects/.virtualenvs/Nprojects/lib/python3.6/site-packages/django/contrib/auth/base_user.py", line 47, in <module>
class AbstractBaseUser(models.Model):
File "/home/projects/.virtualenvs/Nproject/lib/python3.6/site-packages/django/db/models/base.py", line 100, in __new__
app_config = apps.get_containing_app_config(module)
File "/home/projects/.virtualenvs/Nproject/lib/python3.6/site-packages/django/apps/registry.py", line 244, in get_containing_app_config
self.check_apps_ready()
File "/home/projects/.virtualenvs/Nproject/lib/python3.6/site-packages/django/apps/registry.py", line 127, in check_apps_ready
raise AppRegistryNotReady("Apps aren't loaded yet.")
django.core.exceptions.AppRegistryNotReady: Apps aren't loaded yet.
Additional data:
-Django 2.1
-Python 3.6.5
The correct name string for the AUTH_USER_MODEL would be appname.modelname. In your case, I suppose it is 'profile.user' (it could be different if you changed the app name by yourself)
I have a Django project. The packages I use: Django 1.11, Eventlet 0.21.0. Python version is 3.4.3.
There are the following configuration files:
1) The main project's configuration file settings.py. It's main role to import one of the other's two configuration files.
try:
from .settings_local import *
except ImportError:
from .conf.common import *
2) settings_local.py. The purpose of this file to import all the settings from common.py and override those inside the file's body (or add some new settings) for example for testing purposes:
from .conf.common import *
...
3) common.py. The file that contains all the configurations settings.
import eventlet
eventlet.monkey_patch(all=True, MySQLdb=True)
...
When I try to check configuration I get the following error:
./manage.py check
Traceback (most recent call last):
File "./manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/home/vagrant/.virtualenvs/<project_name>/lib/python3.4/site-packages/django/core/management/__init__.py", line 363, in execute_from_command_line
utility.execute()
File "/home/vagrant/.virtualenvs/<project_name>/lib/python3.4/site-packages/django/core/management/__init__.py", line 355, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/vagrant/.virtualenvs/<project_name>/lib/python3.4/site-packages/django/core/management/base.py", line 283, in run_from_argv
self.execute(*args, **cmd_options)
File "/home/vagrant/.virtualenvs/<project_name>/lib/python3.4/site-packages/django/core/management/base.py", line 322, in execute
saved_locale = translation.get_language()
File "/home/vagrant/.virtualenvs/<project_name>/lib/python3.4/site-packages/django/utils/translation/__init__.py", line 195, in get_language
return _trans.get_language()
File "/home/vagrant/.virtualenvs/<project_name>/lib/python3.4/site-packages/django/utils/translation/__init__.py", line 59, in __getattr__
if settings.USE_I18N:
File "/home/vagrant/.virtualenvs/<project_name>/lib/python3.4/site-packages/django/conf/__init__.py", line 56, in __getattr__
self._setup(name)
File "/home/vagrant/.virtualenvs/<project_name>/lib/python3.4/site-packages/django/conf/__init__.py", line 41, in _setup
self._wrapped = Settings(settings_module)
File "/home/vagrant/.virtualenvs/<project_name>/lib/python3.4/site-packages/django/conf/__init__.py", line 110, in __init__
mod = importlib.import_module(self.SETTINGS_MODULE)
File "/home/vagrant/.virtualenvs/<project_name>/lib/python3.4/importlib/__init__.py", line 109, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 2254, in _gcd_import
File "<frozen importlib._bootstrap>", line 2237, in _find_and_load
File "<frozen importlib._bootstrap>", line 2226, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 1200, in _load_unlocked
File "<frozen importlib._bootstrap>", line 1129, in _exec
File "<frozen importlib._bootstrap>", line 1471, in exec_module
File "<frozen importlib._bootstrap>", line 321, in _call_with_frames_removed
File "/vagrant/<project_name>/<project_name>/<project_name>/settings.py", line 2, in <module>
from .settings_local import *
File "/vagrant/<project_name>/<project_name>/<project_name>/settings_local.py", line 1, in <module>
from .conf.common import *
File "/vagrant/<project_name>/<project_name>/<project_name>/conf/common.py", line 3, in <module>
eventlet.monkey_patch(all=True, MySQLdb=True)
File "/home/vagrant/.virtualenvs/<project_name>/lib/python3.4/site-packages/eventlet/patcher.py", line 254, in monkey_patch
_green_existing_locks()
File "/home/vagrant/.virtualenvs/<project_name>/lib/python3.4/site-packages/eventlet/patcher.py", line 345, in _green_existing_locks
if isinstance(obj, rlock_type):
File "/home/vagrant/.virtualenvs/<project_name>/lib/python3.4/site-packages/django/utils/functional.py", line 238, in inner
self._setup()
File "/home/vagrant/.virtualenvs/<project_name>/lib/python3.4/site-packages/django/conf/__init__.py", line 41, in _setup
self._wrapped = Settings(settings_module)
File "/home/vagrant/.virtualenvs/<project_name>/lib/python3.4/site-packages/django/conf/__init__.py", line 129, in __init__
raise ImproperlyConfigured("The SECRET_KEY setting must not be empty.")
django.core.exceptions.ImproperlyConfigured: The SECRET_KEY setting must not be empty.
I figured out that an exception initially occurs in /lib/python3.4/site-packages/eventlet/patcher.py in a function _green_existing_locks() and then propagates up to __init.py__.
Could someone tell me what am I doing wrong?
Please observe the difference between settings and code.
# settings.py
SECRET_KEY = 'abc...'
DEBUG = True
# just a list of constant definitions
# your common.py
eventlet.monkey_patch()
# it's code that changes python environment
# another bad example of settings.py with similar problem
open('/tmp/flag-file-1', 'w')
os.remove('/tmp/flag-file-2')
you don't put side effect generating code into settings. Find a place for initialisation code according to Django guidelines for your version and place monkey_patch() there.
django.core.exceptions.ImproperlyConfigured: The SECRET_KEY setting
must not be empty.
Following error signifies that SECRET_KEY is not set in settings
i' ve Django 1.9.2 with python 3.4.2 in a virtualenvironment.
I' ve many applications, and the 2 related are common and shop.
common/models.py contains:
from django.apps import apps
class Document(CLDate):
user = models.ForeignKey(User)
assessmentorder = models.ForeignKey(apps.get_model('shop', 'AssessmentOrder'), blank=True, null=True)
shop/models.py contains:
from common.models import ServiceModel
class AssessmentOrder(CLDate):
"""AssessmentOrder model"""
order = models.ForeignKey(Order)
comment = models.TextField()
.
This is a circular import, and i read many strategy to resolve it (including apps.get_model), but none of them seem to work for me. I also tried
apps.get_model('shop.AssessmentOrder')
, but the same. The complete error message is the following:
File "/home/hidden/.virtualenvs/sccdb34/lib/python3.4/site-packages/django/utils/autoreload.py", line 226, in wrapper
fn(*args, **kwargs)
File "/home/hidden/.virtualenvs/sccdb34/lib/python3.4/site-packages/django/core/management/commands/runserver.py", line 109, in inner_run
autoreload.raise_last_exception()
File "/home/hidden/.virtualenvs/sccdb34/lib/python3.4/site-packages/django/utils/autoreload.py", line 249, in raise_last_exception
six.reraise(*_exception)
File "/home/hidden/.virtualenvs/sccdb34/lib/python3.4/site-packages/django/utils/six.py", line 685, in reraise
raise value.with_traceback(tb)
File "/home/hidden/.virtualenvs/sccdb34/lib/python3.4/site-packages/django/utils/autoreload.py", line 226, in wrapper
fn(*args, **kwargs)
File "/home/hidden/.virtualenvs/sccdb34/lib/python3.4/site-packages/django/__init__.py", line 18, in setup
apps.populate(settings.INSTALLED_APPS)
File "/home/hidden/.virtualenvs/sccdb34/lib/python3.4/site-packages/django/apps/registry.py", line 108, in populate
app_config.import_models(all_models)
File "/home/hidden/.virtualenvs/sccdb34/lib/python3.4/site-packages/django/apps/config.py", line 202, in import_models
self.models_module = import_module(models_module_name)
File "/home/hidden/.virtualenvs/sccdb34/lib/python3.4/importlib/__init__.py", line 109, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 2254, in _gcd_import
File "<frozen importlib._bootstrap>", line 2237, in _find_and_load
File "<frozen importlib._bootstrap>", line 2226, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 1200, in _load_unlocked
File "<frozen importlib._bootstrap>", line 1129, in _exec
File "<frozen importlib._bootstrap>", line 1471, in exec_module
File "<frozen importlib._bootstrap>", line 321, in _call_with_frames_removed
File "/home/hidden/git/sccdb/sccdb/common/models.py", line 25, in <module>
class Document(CLDate):
File "/home/hidden/git/sccdb/sccdb/common/models.py", line 28, in Document
assessmentorder = models.ForeignKey(apps.get_model('shop.AssessmentOrder'), blank=True, null=True)
File "/home/hidden/.virtualenvs/sccdb34/lib/python3.4/site-packages/django/apps/registry.py", line 194, in get_model
self.check_models_ready()
File "/home/hidden/.virtualenvs/sccdb34/lib/python3.4/site-packages/django/apps/registry.py", line 131, in check_models_ready
raise AppRegistryNotReady("Models aren't loaded yet.")
django.core.exceptions.AppRegistryNotReady: Models aren't loaded yet.
Is it somehow related to my django version or python3, or what am i doing wrong?
Instead of doing using get_model function in foreign key declaration, you can simply put the model name as string and it'll still work:
assessmentorder = models.ForeignKey('shop.AssessmentOrder', blank=True, null=True)
This should resolve the issue
Don't include models, just put a path to them. As it described in docs
from django.conf import settings
class Document(CLDate):
user = models.ForeignKey(settings.AUTH_USER_MODEL)
assessmentorder = models.ForeignKey('shop.AssessmentOrder', blank=True, null=True)
And
class AssessmentOrder(CLDate):
"""AssessmentOrder model"""
order = models.ForeignKey('yourapp.Order')
comment = models.TextField()