I have a django rest framework project already going with some models already created, and I am trying to add django-modeltranslation to the project. I followed the process as specified in django-modeltranslation documentation, but applications stop working after making migrations with django-modeltranslation modifications.
Everytime I try to access de database, wether through the admin page or the django rest framework page, I get an error with the applications I have added transalation.py
file to. Applications without it continue working.
This is my model:
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
This is my translation.py
@register(models.Country)
class CountryTranslationOptions(TranslationOptions):
fields = ('name',)
And this is the whole traceback of the error I get:
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
I would appreciate any help.
Googling the error ( ;) ) led me to https://github.com/deschler/django-modeltranslation/issues/436 – if I'm assuming correctly, you're using Django 2.0, and no released version of django-modeltranslation supports it yet.