django-modeltranslation导致django无法访问数据库
django-modeltranslation causes django unable to access database
我有一个 django rest 框架项目,其中已经创建了一些模型,我正在尝试将 django-modeltranslation 添加到项目中。我按照 django-modeltranslation 文档中指定的过程进行操作,但应用程序在使用 django-modeltranslation 修改进行迁移后停止工作。
每次我尝试访问 de 数据库时,无论是通过管理页面还是 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 版本支持它。
我有一个 django rest 框架项目,其中已经创建了一些模型,我正在尝试将 django-modeltranslation 添加到项目中。我按照 django-modeltranslation 文档中指定的过程进行操作,但应用程序在使用 django-modeltranslation 修改进行迁移后停止工作。
每次我尝试访问 de 数据库时,无论是通过管理页面还是 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 版本支持它。