TypeError:'MediaDefiningClass'对象不可迭代

时间:2018-04-07 20:31:42

标签: django

我正在尝试实现django-progressbarupload。

https://github.com/ouhouhsami/django-progressbarupload

我收到以下错误:

for model_or_iterable中的模型: TypeError:'MediaDefiningClass'对象不可迭代

admin.py

from django.contrib import admin
from accounts.models import UserProfile

class UserProfile(admin.ModelAdmin):
    change_form_template = 'progressbarupload/change_form.html'
    add_form_template = 'progressbarupload/change_form.html'

admin.site.register(UserProfile)

这是追溯

Traceback (most recent call last):
  File "manage.py", line 15, in <module>
    execute_from_command_line(sys.argv)
  File "C:\Users\jason\AppData\Local\Programs\Python\Python36\lib\site-packages\django\core\management\__init__.py", line 371, in execute_from_command_line
    utility.execute()
  File "C:\Users\jason\AppData\Local\Programs\Python\Python36\lib\site-packages\django\core\management\__init__.py", line 347, in execute
    django.setup()
  File "C:\Users\jason\AppData\Local\Programs\Python\Python36\lib\site-packages\django\__init__.py", line 24, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "C:\Users\jason\AppData\Local\Programs\Python\Python36\lib\site-packages\django\apps\registry.py", line 120, in populate
    app_config.ready()
  File "C:\Users\jason\AppData\Local\Programs\Python\Python36\lib\site-packages\django\contrib\admin\apps.py", line 23, in ready
    self.module.autodiscover()
  File "C:\Users\jason\AppData\Local\Programs\Python\Python36\lib\site-packages\django\contrib\admin\__init__.py", line 26, in autodiscover
    autodiscover_modules('admin', register_to=site)
  File "C:\Users\jason\AppData\Local\Programs\Python\Python36\lib\site-packages\django\utils\module_loading.py", line 47, in autodiscover_modules
    import_module('%s.%s' % (app_config.name, module_to_search))
  File "C:\Users\jason\AppData\Local\Programs\Python\Python36\lib\importlib\__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 994, in _gcd_import
  File "<frozen importlib._bootstrap>", line 971, in _find_and_load
  File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 678, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "C:\Users\jason\Desktop\jason3\accounts\admin.py", line 18, in <module>
    admin.site.register(UserProfile)
  File "C:\Users\jason\AppData\Local\Programs\Python\Python36\lib\site-packages\django\contrib\admin\sites.py", line 102, in register
    for model in model_or_iterable:
TypeError: 'MediaDefiningClass' object is not iterable

感谢您的帮助!

1 个答案:

答案 0 :(得分:3)

register的第一个参数是模型类本身。您的模型类使用与管理类相同的名称。给它们单独的名称并将它们传递给register

class UserProfileAdmin(admin.ModelAdmin):
    change_form_template = 'progressbarupload/change_form.html'
    add_form_template = 'progressbarupload/change_form.html'

admin.site.register(UserProfile, UserProfileAdmin)