#24885: Writing your first Django app, part 1 -> def __str__(self): problem or
misunderstanding of doc?
-------------------------------------+-------------------------------------
     Reporter:  TitanFighter         |      Owner:  TitanFighter
         Type:                       |     Status:  new
  Cleanup/optimization               |
    Component:  Documentation        |    Version:  1.8
     Severity:  Normal               |   Keywords:  Writing your first
                                     |  Django app, part 1, tutorial,
                                     |  [<Question: Question object>]
 Triage Stage:  Unreviewed           |  Has patch:  0
Easy pickings:  0                    |      UI/UX:  0
-------------------------------------+-------------------------------------
 Hi guys.
 I have a problem with the tutorial "Writing your first Django app, part 1"
 starting from position:
 {{{
 >>> from polls.models import Question, Choice

 # Make sure our __str__() addition worked.
 >>> Question.objects.all()
 [<Question: What's up?>]

 # Django provides a rich database lookup API that's entirely driven by
 # keyword arguments.
 >>> Question.objects.filter(id=1)
 [<Question: What's up?>]
 >>> Question.objects.filter(question_text__startswith='What')
 [<Question: What's up?>]
 }}}

 In all cases I receive:
 [<Question: Question object>]  instead of [<Question: What's up?>]

 I have Ubuntu 15.04_64 and run Python 3.4.3 via "python3 manage.py shell",
 because Ubuntu has built-in Python 2.*

 My code is like:
 {{{
 import datetime

 from django.db import models
 from django.utils import timezone

 class Question(models.Model):
         question_text = models.CharField(max_length=200)
         pub_date = models.DateTimeField('date published')

         def __str__(self):              # __unicode__ on Python 2
                 return self.question_text

         def was_published_recently(self):
                 return self.pub_date >= timezone.now() -
 datetime.timedelta(days=1)

 class Choice(models.Model):
         question = models.ForeignKey(Question)
         choice_text = models.CharField(max_length=200)
         votes = models.IntegerField(default=0)

         def __str__(self):              # __unicode__ on Python 2
                 return self.choice_text
 }}}

 If something wrong with the code, maybe is it possible to edit this
 section in tutorial to make it a bit clearer? Or is this problem somewhere
 else?
 Thanks.

--
Ticket URL: <https://code.djangoproject.com/ticket/24885>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-updates+unsubscr...@googlegroups.com.
To post to this group, send email to django-updates@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/055.cbe7080db9e033baa2b0e08cfc956306%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to