0👍
It looks like django-modeltranslation doesn’t workwith django 2.0 (at least for me and the installation procedure out there). But it does with django 1.11.
8👍
I had the similar problem with django-modeltranslation.
In Django 2.0.5 I had an error when I opened the admin panel.
Need to update package:
pip install django-modeltranslation==0.13-beta1
update the translations:
python manage.py update_translation_fields
And everything works fine.
- [Django]-Humanize in django/python, how to translate
- [Django]-How to correctly load data from a table to a form?
- [Django]-Django-allauth adapter redirects
- [Django]-What is the settings for django rest framework swagger open api security object definition for oauth2 flow being password?
1👍
OP is using django-modeltranslation
with Django
2.0. But their tests are currently failing for this version.
Use ugettext_lazy
in your settings.py
to avoid circular imports:
from django.utils.translation import ugettext_lazy as _
LANGUAGES = [
('en', _('English')),
('th', _('Thai')),
]
MODELTRANSLATION_DEFAULT_LANGUAGE = 'en'
MODELTRANSLATION_LANGUAGES = ('en', 'th')
Try to put your modeltranslation
at the end of your INSTALLED_APPS
, after the django
defaults.
Have you registered your model somewhere else? You can try to unregister it before you register it again.
admin.site.unregister(News)
admin.site.register(News, NewsAdmin)
Are you following the steps with python manage.py makemigration
, as stated in the docs?
1👍
It seems "modeltranslations" is no longer being maintained at that particular library name. And later versions of django require on_delete to be set for models.ForeignKey
For me this worked:
pip uninstall modeltranslations
pip install django-modeltranslations
As far as I can tell it’s the same library, but you get a newer version. In my case, I did not need to modify settings.py at all.
- [Django]-Django Rest Framework doesn't accept ArrayField POST
- [Django]-Customize queryset in django-filter ModelChoiceFilter (select) and ModelMultipleChoiceFilter (multi-select) menus based on request
0👍
Did you try the sync_translation_fields
Management Command?
This command compares the database and translated models definitions (finding new translation fields) and provides SQL statements to alter tables. You should run this command after adding a new language to your
settings.LANGUAGES
or a new field to theTranslationOptions
of a registered model.
- [Django]-A better way to get only specific attributes from a Django queryset?
- [Django]-Unknown command: 'collectstatic' Django 1.7
- [Django]-How to use date__range filter efficiently in django
- [Django]-Django invite code app recommendation?
0👍
My configuration: Django 2.2.5, Python 3.7.4, bootstrap4-0.1.0
edit ~/anaconda3/envs/django/lib/python3.7/site-packages/modeltranslation/models.py, add on_delete=models.CASCADE
creator_user = models.ForeignKey(User, null=True, default=None, related_name='model_translation', verbose_name=u"User translator", help_text=u"User that created last translation version", on_delete=models.CASCADE,)
edit /anaconda3/envs/django/lib/python3.7/site-packages/modeltranslation/migrations/0001_initial.py, add
import django.db.models.deletion
and on_delete=django.db.models.deletion.CASCADE,
from django.db import models, migrations
import django.db.models.deletion
('creator_user', models.ForeignKey(related_name='model_translation', default=None, on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL, help_text='Usuario que ha realizado la \xfaltima traducci\xf3n', null=True, verbose_name='Usuario que ha realizado la traducci\xf3n')),
In settings.py
# ModelTranslation
IS_MONOLINGUAL=False
TRANSLATABLE_MODEL_MODULES = ["marketplace.models"]
Modify this with your apps name,
TRANSLATABLE_MODEL_MODULES = [“.models”]
$ python manage.py makemigrations
$ python manage.py migrate
Hope it works for your case too.
- [Django]-Admin site uses default database in Django 1.6
- [Django]-How can I limit http method to a Django REST api
- [Django]-Django application deployed at suburl, redirect to home page after login