这是我的translation.py文件:
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);
模型.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