我正在将现有模型/管理员转换为django-polymorphic。我认为我已成功完成模型和迁移(至少,它在shell中工作)但我无法让管理员工作。我发现documentation有点模糊,但我想我已经正确地遵循了它。
class LibraryItemAdmin(PolymorphicParentModelAdmin):
base_model = LibraryItem
child_models = (Whitepaper)
class LibraryItemChildAdmin(PolymorphicChildModelAdmin):
base_model = LibraryItem
class WhitepaperAdmin(LibraryItemChildAdmin):
form = LibraryForm
base_model = Whitepaper
我不明白这个问题:
Traceback:
File "/root/.virtualenvs/divesite/local/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response
108. response = middleware_method(request)
File "/root/.virtualenvs/divesite/local/lib/python2.7/site-packages/django/middleware/common.py" in process_request
74. if (not urlresolvers.is_valid_path(request.path_info, urlconf) and
File "/root/.virtualenvs/divesite/local/lib/python2.7/site-packages/django/core/urlresolvers.py" in is_valid_path
646. resolve(path, urlconf)
File "/root/.virtualenvs/divesite/local/lib/python2.7/site-packages/django/core/urlresolvers.py" in resolve
521. return get_resolver(urlconf).resolve(path)
File "/root/.virtualenvs/divesite/local/lib/python2.7/site-packages/django/core/urlresolvers.py" in resolve
365. for pattern in self.url_patterns:
File "/root/.virtualenvs/divesite/local/lib/python2.7/site-packages/django/core/urlresolvers.py" in url_patterns
401. patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
File "/root/.virtualenvs/divesite/local/lib/python2.7/site-packages/django/core/urlresolvers.py" in urlconf_module
395. self._urlconf_module = import_module(self.urlconf_name)
File "/usr/lib/python2.7/importlib/__init__.py" in import_module
37. __import__(name)
File "/srv/www/urls.py" in <module>
349. url(r'^admin/', include(admin.site.urls), name='admin'),
File "/root/.virtualenvs/divesite/local/lib/python2.7/site-packages/django/contrib/admin/sites.py" in urls
291. return self.get_urls(), 'admin', self.name
File "/root/.virtualenvs/divesite/local/lib/python2.7/site-packages/django/contrib/admin/sites.py" in get_urls
275. url(r'^%s/%s/' % (model._meta.app_label, model._meta.model_name), include(model_admin.urls)),
File "/root/.virtualenvs/divesite/local/lib/python2.7/site-packages/django/contrib/admin/options.py" in urls
631. return self.get_urls()
File "/root/.virtualenvs/divesite/local/lib/python2.7/site-packages/polymorphic/admin/parentadmin.py" in get_urls
283. self._lazy_setup()
File "/root/.virtualenvs/divesite/local/lib/python2.7/site-packages/polymorphic/admin/parentadmin.py" in _lazy_setup
92. self._compat_mode = len(child_models) and isinstance(child_models[0], (list, tuple))
Exception Type: TypeError at /admin/library
Exception Value: object of type 'PolymorphicModelBase' has no len()
答案 0 :(得分:0)
文档已过期。糟糕的文档。坏。
child_models应该是(Model,ModelAdmin)元组的可迭代。
https://github.com/django-polymorphic/django-polymorphic/issues/227