python - django-modeltranslation 导致 django 无法访问数据库
问题描述
我有一个 django rest 框架项目,已经创建了一些模型,我正在尝试将 django-modeltranslation 添加到项目中。我遵循了 django-modeltranslation 文档中指定的过程,但是在使用 django-modeltranslation 修改进行迁移后,应用程序停止工作。
每次我尝试访问数据库时,无论是通过管理页面还是 django rest 框架页面,我都会在添加transalation.py
文件的应用程序中遇到错误。没有它的应用程序将继续工作。
这是我的模型:
class Country(models.Model):
name = models.CharField(max_length=40, unique=True, verbose_name=_('Name'))
code = models.CharField(max_length=5, verbose_name=_('Code'))
calling_code = models.CharField(max_length=3, null=True, blank=True, verbose_name=_('Calling code'))
class Meta:
verbose_name = _('Country')
verbose_name_plural = _('Countries')
def __str__(self):
return self.name
这是我的translation.py
@register(models.Country)
class CountryTranslationOptions(TranslationOptions):
fields = ('name',)
这是我得到的错误的全部追溯:
Internal Server Error: /es/general/countries/
Traceback (most recent call last):
File "/Users/hugovillalobos/Documents/Code/IntellibookProject/IntellibookVenv/lib/python3.6/site-packages/django/core/handlers/exception.py", line 35, in inner
response = get_response(request)
File "/Users/hugovillalobos/Documents/Code/IntellibookProject/IntellibookVenv/lib/python3.6/site-packages/django/core/handlers/base.py", line 128, in _get_response
response = self.process_exception_by_middleware(e, request)
File "/Users/hugovillalobos/Documents/Code/IntellibookProject/IntellibookVenv/lib/python3.6/site-packages/django/core/handlers/base.py", line 126, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/Users/hugovillalobos/Documents/Code/IntellibookProject/IntellibookVenv/lib/python3.6/site-packages/django/views/decorators/csrf.py", line 54, in wrapped_view
return view_func(*args, **kwargs)
File "/Users/hugovillalobos/Documents/Code/IntellibookProject/IntellibookVenv/lib/python3.6/site-packages/rest_framework/viewsets.py", line 103, in view
return self.dispatch(request, *args, **kwargs)
File "/Users/hugovillalobos/Documents/Code/IntellibookProject/IntellibookVenv/lib/python3.6/site-packages/rest_framework/views.py", line 483, in dispatch
response = self.handle_exception(exc)
File "/Users/hugovillalobos/Documents/Code/IntellibookProject/IntellibookVenv/lib/python3.6/site-packages/rest_framework/views.py", line 443, in handle_exception
self.raise_uncaught_exception(exc)
File "/Users/hugovillalobos/Documents/Code/IntellibookProject/IntellibookVenv/lib/python3.6/site-packages/rest_framework/views.py", line 480, in dispatch
response = handler(request, *args, **kwargs)
File "/Users/hugovillalobos/Documents/Code/IntellibookProject/IntellibookVenv/lib/python3.6/site-packages/rest_framework/mixins.py", line 40, in list
queryset = self.filter_queryset(self.get_queryset())
File "/Users/hugovillalobos/Documents/Code/IntellibookProject/IntellibookVenv/lib/python3.6/site-packages/rest_framework/generics.py", line 74, in get_queryset
queryset = queryset.all()
File "/Users/hugovillalobos/Documents/Code/IntellibookProject/IntellibookVenv/lib/python3.6/site-packages/django/db/models/query.py", line 829, in all
return self._chain()
File "/Users/hugovillalobos/Documents/Code/IntellibookProject/IntellibookVenv/lib/python3.6/site-packages/django/db/models/query.py", line 1156, in _chain
obj = self._clone()
File "/Users/hugovillalobos/Documents/Code/IntellibookProject/IntellibookVenv/lib/python3.6/site-packages/modeltranslation/manager.py", line 234, in _clone
return super(MultilingualQuerySet, self)._clone(**kwargs)
TypeError: _clone() got an unexpected keyword argument '_rewrite'
[05/Jun/2018 15:54:13] "GET /es/general/countries/ HTTP/1.1" 500 99097
我将不胜感激任何帮助。
解决方案
谷歌搜索错误(;))导致我到https://github.com/deschler/django-modeltranslation/issues/436 - 如果我假设正确,您使用的是 Django 2.0,并且没有发布版本的 django-modeltranslation还支持它。
推荐阅读
- firebase-authentication - 在使用 Firebase 作为身份验证提供程序时配置密码重用策略和密码强度
- angular - Angular 在 ngFor 循环搜索重复项中使用管道过滤器
- sql - SQL sp_addextendedproperty 问题
- docker - 为 nexus 存储库中的 docker 图像设置自定义清理
- html - 当屏幕最小化时,如何将主要内容与响应式菜单对齐?
- python - 如何使用电子表格中的两个不同列制作按图分组的条形图?
- javascript - 在无限滑块轨道动画上使用 Element.prepend 的意外 DOM 排序行为
- r - R标记中的双标图由两个变量?
- sql - 如何检查一列中的数据在另一列中不存在
- android - 如何将 Google Barcode 添加到片段内的 android 应用程序?