Django unicode method not working
Question: I am following the app tutorial on the Django website and using **_Python
2.7.5_** with **_Django 1.8_**. It suggests Python 2.7 users to include a
**unicode** method in the models.py file to return readable output in the
python shell.

# I have added the unicode method into the Question and Choice classes as so:

    
    
    from django.db import models
    import datetime
    from django.utils import timezone
    from django.util.encoding import python_2_unicode_compatible
    
    class Question(models.Model):
        question_text = models.CharField(max_length=200)
        pub_date = models.DateTimeField('date published')
    
        def was_published_recently(self):
            return self.pub_date >= timezone.now() - datetime.timedelta(days = 1)
    
        def __unicode__(self):
            return u"%i" % self.question_text
    
        def __str__(self):
            return question_text
    
    class Choice(models.Model):
        question = models.ForeignKey(Question)
    
        choice_text = models.CharField(max_length=200)
    
        votes = models.IntegerField(default=0)
    
        def __unicode__(self):
            return u"%i" % self.choice_text
        def __str__(self):
            return choice_text
    

**_This is my output from the python shell:_**

    
    
    from polls.models import Question, Choice
    >>> Question.objects.all()
    [<Question: Question object>]
    >>> 
    

**_When it really should be this:_**

    
    
    >>> Question.objects.all()
    [<Question: What's up?>]
    

I don't understand what I am doing wrong. Please help!


Answer: Neither the `was_published_recently` nor the `__unicode__` method are within
the Question class. Indentation is significant: make sure they are indented to
the same level as the fields.

