0
我是新的模型翻譯,我有一個問題。在創建我的模型並註冊要在translation.py中翻譯的字段後,當我執行manage.py makemigrations myapp命令時,模型翻譯應用程序不會將翻譯的字段添加到模型中。字段在表格中。Django,Django模型翻譯
modeltranslation:Registered 0 models for translation()[pid:8333]。
我setting.pyfrom django.utils.translation import ugettext_lazy as _
gettext = lambda s: s
LANGUAGES = (
('hi', _('Hindi')),
('en', _('English')),
('ru', _('Russian')),
('ur', _('Urdu')),
('zh', _('Chinese')),
)
LOCALE_PATHS = (
os.path.join(BASE_DIR, 'locale'),
)
LANGUAGE_CODE = 'hi'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_L10N = True
USE_TZ = True
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.8/howto/static-files/
from modeltranslation.translator import translator
STATIC_URL = '/static/'
MODELTRANSLATION_DEFAULT_LANGUAGE = 'hi'
MODELTRANSLATION_LANGUAGES = ('hi', 'en')
MODELTRANSLATION_FALLBACK_LANGUAGES = ('hi', 'en')
MODELTRANSLATION_PREPOPULATE_LANGUAGE = 'hi'
MODELTRANSLATION_TRANSLATION_FILES = (
'i18ntest.translation',
)
在我的models.py
from django.db import models
from django.utils.translation import ugettext_lazy
from django.conf import settings
class MyThing(models.Model):
name = models.CharField(help_text=ugettext_lazy('This is the help text'),max_length = 150,null = True, blank = True)
def __unicode__(self):
return self.name
# Create your models here.
class Profile(models.Model):
name = models.CharField(max_length = 150,null = True, blank = True)
def __unicode__(self):
return self.name
在我translations.py
from modeltranslation.translator import register,translator, TranslationOptions
from i18ntest.models import MyThing
@register(MyThing)
class MyThingTranslationOptions(TranslationOptions):
fields = ('name',
)
#translator.register(MyThing, MyThingTranslationOptions)
我使用的Django modeltranslation 0.12和Django 1.10
和服務器狀態爲
(envi18n) [email protected]:~/vinod/i18n/i18n$ ./manage.py runserver
modeltranslation: Registered 0 models for translation() [pid: 9065].
modeltranslation: Registered 0 models for translation() [pid: 9068].
Performing system checks...
System check identified no issues (0 silenced).
February 22, 2017 - 12:26:35
Django version 1.10, using settings 'i18n.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.