一。报异常 ‘DateTimeField‘ object has no attribute ‘rel‘
修改 xadmin\views/list.py 中228行
if isinstance(field.rel, models.ManyToOneRel):
related_fields.append(field_name)
修改为
if isinstance(field.remote_field, models.ManyToOneRel):
related_fields.append(field_name)
PS:凡是报异常rel的地方都可以尝试将报错方法中的.rel 修改为.remote_field
二。手动添加系统日志时报异常: 'ManyToOneRel' object has no attribute 'to'
修改 xadmin\plugins\quickform.py 中80行
self.add_url, (_('Create New %s') % self.rel.to._meta.verbose_name), name,
修改为
self.add_url, (_('Create New %s') % self.rel), name,
三。报异常:Exception: Relate Lookup field must a related field
修改 xadmin\util.py 中 495行
return (hasattr(field, 'rel') and field.rel != None) or is_related_field(field)
修改为
return (hasattr(field, 'remote_field') and field.remote_field != None) or is_related_field(field)
四。登录或注销时报异常:logout() got an unexpected keyword argument 'current_app' 或 login() got an unexpected keyword argument 'current_app'
修改xadmin\views\website.py 中61、87行
注释掉:# 'current_app': self.admin_site.name,
五。国际化问题报异常:ImportError: cannot import name 'javascript_catalog' from 'django.views.i18n' (E:\PYDjango\seafood\venv\lib\site-packages\django\views\i18n.py)
此异常会导致 adminx.py中的show_detail_fields 设置无效
由于django2.x中该javascript_catalog方法不存在,引起详情界面(xadmin.plugin.details.js)的JS代码执行异常,以下gettext()方法无法执行
当点击详情图标时,就无法正常弹出详情界面窗口
方法1:临时解决办法(此方法按钮显示为英文),修改xadmin\sites.py中348行,注释掉
#if settings.USE_I18N:
# from django.views.i18n import javascript_catalog
#else:
# from django.views.i18n import null_javascript_catalog as javascript_catalog
添加行
from django.views.i18n import null_javascript_catalog as javascript_catalog
方法2:同样注释掉上面的代码(同方法1,此方法按钮仍显示为英文)
添加行
from django.views.i18n import JavaScriptCatalog
return JavaScriptCatalog.as_view(packages=['django.conf'])(request)
方法3:不修改xadmin\sites.py,只修改django\views\i18n.py(此方法按钮显示为中文)。
先在settings.py -- INSTALLED_APPS=[...] 中添加 'django.conf'(否则会报异常Invalid package(s) provided to JavaScriptCatalog:...)
再去git上找django1.9.x分支(https://github.com/django/django/blob/stable/1.9.x/django/views/i18n.py),将django\views\i18n.py文件中的代码复制到本地项目django2.X(记得保留JavaScriptCatalog这个类)的同名文件中。具体操作先从复制javascript_catalog这个方法开始,然后根据错误提示一步步补全剩余的代码,直到没有报错为止,这样就完美解决了显示中文问题。