2015-03-08 2 views
0

Итак, я пытаюсь расширить модель пользователя с помощью OneToOneField, но также изменить UserAdmin, чтобы отобразить правильную информацию, в которой я столкнулся с моей ошибкой. время импортироватьИмпортирование UserAdmin повышается AppRegistryNotReady («Модели еще не загружены».)

from django.contrib.auth.admin import UserAdmin 

Я получаю эту ошибку:

Traceback (most recent call last): 
File "C:\Program Files (x86)\JetBrains\PyCharm3.4.1\helpers\pycharm\django_manage.py", line 23, in <module> 
run_module(manage_file, None, '__main__', True) 
File "C:\Python27\lib\runpy.py", line 176, in run_module 
fname, loader, pkg_name) 
File "C:\Python27\lib\runpy.py", line 82, in _run_module_code 
mod_name, mod_fname, mod_loader, pkg_name) 
File "C:\Python27\lib\runpy.py", line 72, in _run_code 
exec code in run_globals 
File "C:\Users\xXxKillDogxXx\Desktop\MinecraftMarket\manage.py", line 10, in <module> 
execute_from_command_line(sys.argv) 
File "C:\Users\xXxKillDogxXx\AppData\Roaming\Python\Python27\site-packages\django\core\management\__init__.py", line 385, in execute_from_command_line 
utility.execute() 
File "C:\Users\xXxKillDogxXx\AppData\Roaming\Python\Python27\site-packages\django\core\management\__init__.py", line 354, in execute 
django.setup() 
File "C:\Users\xXxKillDogxXx\AppData\Roaming\Python\Python27\site-packages\django\__init__.py", line 21, in setup 
apps.populate(settings.INSTALLED_APPS) 
File "C:\Users\xXxKillDogxXx\AppData\Roaming\Python\Python27\site-packages\django\apps\registry.py", line 85, in populate 
app_config = AppConfig.create(entry) 
File "C:\Users\xXxKillDogxXx\AppData\Roaming\Python\Python27\site-packages\django\apps\config.py", line 87, in create 
module = import_module(entry) 
File "C:\Python27\lib\importlib\__init__.py", line 37, in import_module 
__import__(name) 
File "C:/Users/xXxKillDogxXx/Desktop/MinecraftMarket\market\__init__.py", line 2, in <module> 
from django.contrib.auth.admin import UserAdmin 
File "C:\Users\xXxKillDogxXx\AppData\Roaming\Python\Python27\site-packages\django\contrib\auth\admin.py", line 184, in <module> 
admin.site.register(User, UserAdmin) 
File "C:\Users\xXxKillDogxXx\AppData\Roaming\Python\Python27\site-packages\django\contrib\admin\sites.py", line 99, in register 
admin_class.check(model) 
File "C:\Users\xXxKillDogxXx\AppData\Roaming\Python\Python27\site-packages\django\contrib\admin\options.py", line 153, in check 
return cls.checks_class().check(cls, model, **kwargs) 
File "C:\Users\xXxKillDogxXx\AppData\Roaming\Python\Python27\site-packages\django\contrib\admin\checks.py", line 497, in check 
errors.extend(self._check_list_filter(cls, model)) 
File "C:\Users\xXxKillDogxXx\AppData\Roaming\Python\Python27\site-packages\django\contrib\admin\checks.py", line 668, in _check_list_filter 
for index, item in enumerate(cls.list_filter) 
File "C:\Users\xXxKillDogxXx\AppData\Roaming\Python\Python27\site-packages\django\contrib\admin\checks.py", line 713, in _check_list_filter_item 
get_fields_from_path(model, field) 
File "C:\Users\xXxKillDogxXx\AppData\Roaming\Python\Python27\site-packages\django\contrib\admin\utils.py", line 457, in get_fields_from_path 
fields.append(parent._meta.get_field_by_name(piece)[0]) 
File "C:\Users\xXxKillDogxXx\AppData\Roaming\Python\Python27\site-packages\django\db\models\options.py", line 416, in get_field_by_name 
cache = self.init_name_map() 
File "C:\Users\xXxKillDogxXx\AppData\Roaming\Python\Python27\site-packages\django\db\models\options.py", line 445, in init_name_map 
for f, model in self.get_all_related_m2m_objects_with_model(): 
File "C:\Users\xXxKillDogxXx\AppData\Roaming\Python\Python27\site-packages\django\db\models\options.py", line 563, in get_all_related_m2m_objects_with_model 
cache = self._fill_related_many_to_many_cache() 
File "C:\Users\xXxKillDogxXx\AppData\Roaming\Python\Python27\site-packages\django\db\models\options.py", line 577, in _fill_related_many_to_many_cache 
for klass in self.apps.get_models(): 
File "C:\Users\xXxKillDogxXx\AppData\Roaming\Python\Python27\site-packages\django\utils\lru_cache.py", line 101, in wrapper 
result = user_function(*args, **kwds) 
File "C:\Users\xXxKillDogxXx\AppData\Roaming\Python\Python27\site-packages\django\apps\registry.py", line 168, in get_models 
self.check_models_ready() 
File "C:\Users\xXxKillDogxXx\AppData\Roaming\Python\Python27\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. 

Вот файл, в котором я пытаюсь изменить UserAdmin, который был скопирован из Джанго Docs:

from django.contrib import admin 
from django.contrib.auth.admin import UserAdmin 
from django.contrib.auth.models import User 
from market.models import Market, MarketThemes, MarketServers, PremiumTransaction, PremiumUser, PremiumCodes, Themes, Templates, AdditionalUserSettings 

class MarketAdmin(admin.ModelAdmin): 
    search_fields = ['marketName', 'cName'] 
    list_display = ('owner', 'marketName', 'marketTheme', 'marketTemplates', 'subDomain', 'cName', 'currency', 'createdDate') 


admin.site.register(Market,MarketAdmin) 

class ThemeAdmin(admin.ModelAdmin): 
    search_fields = ['title'] 
    list_display = ('owner', 'marketid', 'title', 'default') 

admin.site.register(Themes,ThemeAdmin) 

class ServersAdmin(admin.ModelAdmin): 
    search_fields = ['serverName', 'apiKey'] 
    list_display = ('owner', 'marketid', 'serverName', 'apiKey') 

admin.site.register(MarketServers,ServersAdmin) 

admin.site.register(Templates) 
admin.site.register(PremiumTransaction) 
admin.site.register(PremiumUser) 

class AdditionalUserSettingsInline(admin.StackedInline): 
    model = AdditionalUserSettings 
    can_delete=False 


class CustomUserAdmin(UserAdmin): 
    inlines = (AdditionalUserSettingsInline,) 

admin.site.unregister(User) 
admin.site.register(User, CustomUserAdmin) 
+0

Возможный дубликат [МОДЕЛИ НЕ НАГРУЖЕНА ПОЛУЧИТЬ ошибку при заполнении в django1.8 и python2.7.8] (http://stackoverflow.com/questions/25244631/models-arent-loaded-yet-error-while- populating-in-django1-8-and-python2-7-8) – rnevius

+0

Не из того, что я вижу, поскольку мне не нужно импортировать это в __init__.py –

ответ

1

Вы должны определить администратора в файле market/admin.py вместо market/__init__.py.

+0

. Исправит ли это ошибку или это скорее код комментарий структуры? –

+0

Да, это исправит ошибку. Фактически 'admin.py' - это место для работы с ModelAdmins. – catavaran

+0

Awesome Ill попробуйте прямо сейчас две секунды, почему это так чувствительно? –

Смежные вопросы