This is my translation.py file:
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
When I open the app, the models' text is not visible. One of the questions is "Coke or Sprite?", but I can't see the text. What am I doing wrong?
Python 3.4, Django 1.10