2017-07-25 77 views
0

文字這是我translation.py文件:Django的modeltranslation去除模型

from modeltranslation.translator import translator, TranslationOptions 
from polls.models import Question, Choice 

class QuestionTranlationOptions(TranslationOptions): 
    fields = ('question_text',) 

class ChoiceTranslationOptions(TranslationOptions): 
    fields = ('choice_text',) 

translator.register(Question, QuestionTranlationOptions) 
translator.register(Choice, ChoiceTranslationOptions); 

models.py

from django.db import models 
from django.utils import timezone 
import datetime 
from django.utils.translation import ugettext_lazy as _ 

class Question(models.Model): 
    question_text = models.CharField(max_length=200) 
    pub_date = models.DateTimeField(_('date published')) 
    def __str__(self): 
     return self.question_text 
    def was_published_recently(self): 
     now = timezone.now() 
     return now - datetime.timedelta(days=1) <= self.pub_date <= now 
    was_published_recently.admin_order_field = 'pub_date' 
    was_published_recently.boolean = True 
    was_published_recently.short_description = _('Published recently?') 

class Choice(models.Model): 
    question = models.ForeignKey(Question, on_delete=models.CASCADE) 
    choice_text = models.CharField(max_length=200) 
    votes = models.IntegerField(default=0) 
    def __str__(self): 
     return self.choice_text 

當我打開應用程序,模特們的文字不可見。其中一個問題是「可樂或雪碧?」,但我看不到文字。我究竟做錯了什麼?

的Python 3.4, Django的1.10

+0

我投票關閉這一問題作爲題外話,因爲用戶只在發佈之前忘了閱讀FineManual ... –

回答

0

我不得不運行此命令來修復它:

C:\Users\xxx\myproject>manage.py update_translation_fields