我有一个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
我将不胜感激。
答案 0 :(得分:0)
谷歌搜索错误(;)导致我https://github.com/deschler/django-modeltranslation/issues/436 - 如果我假设正确,你正在使用Django 2.0,并且没有发布版本的django-modeltranslation支持它。