Search code examples
pythondjangodjango-modeltranslation

Error in db with modeltranslation in django


I want to add internationalization to a project, so I use django-modeltranslation app. However, after following all the steps of configuration and running migrations, when I enter in my admin the model is registered, but when I click on it:

"Something's wrong with your database installation. Make sure the appropriate database tables have been created, and make sure the database is readable by the appropriate user."

Here's the code (note I have put it all in a file for clarity):

INSTALLED_APPS = [
    'modeltranslation',
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',

    'nuggets',
]

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql',
        'NAME': 'Trans',
        'USER': 'postgres',
        'PASSWORD': 'c1l2a3u4',
        'HOST': '127.0.0.1',
        'PORT': '5432',
    }
}


LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_L10N = True

USE_TZ = True

gettext = lambda s: s
LANGUAGES = (
    ('en', gettext('English')),
    ('es', gettext('Spanish')),
)

#Models code
from django.db import models
class News(models.Model):
    title = models.CharField(max_length=255)
    text = models.TextField()


#Admin code
from django.contrib import admin
from .models import News
from modeltranslation.admin import TranslationAdmin

class NewsAdmin(TranslationAdmin):
	pass

admin.site.register(News, NewsAdmin)


#translation.py code
from modeltranslation.translator import translator, TranslationOptions
from .models import News

class NewsTranslationOptions(TranslationOptions):
    fields = ('title', 'text',)

translator.register(News, NewsTranslationOptions)

]2]2

I have tried before createing the models, after, with default db, with postgre... Nothing seems to work, help please!


Solution

  • 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.