Issue Setting Up Django Database Access API Using SQLite
Question: I just started using Django, and I am going through the documentation
[here](https://docs.djangoproject.com/en/1.8/intro/tutorial01/) to build my
first app, but I am running into some kind of issue related to the database
access API for SQLite.

My directory structure looks like this:

[![](http://i.stack.imgur.com/AI1Fu.png)](http://i.stack.imgur.com/AI1Fu.png)

The only files I have edited are `models.py` and `settings.py` and it is all
code from the documentation.

models.py:

    
    
    from django.db import models
    
    class Question(models.Model):
        # ...
        def __str__(self):              # __unicode__ on Python 2
            return self.question_text
    
    class Choice(models.Model):
        # ...
        def __str__(self):              # __unicode__ on Python 2
            return self.choice_text
    
    import datetime
    
    from django.db import models
    from django.utils import timezone
    
    
    class Question(models.Model):
        # ...
        def was_published_recently(self):
            return self.pub_date >= timezone.now() - datetime.timedelta(days=1)
    

The only changes I have made to `settings.py` are adding my timezone
`TIME_ZONE = 'US/Pacific'` and adding `'polls',` to `INSTALLED_APPS`.

(For full disclosure, I have set up my `urls.py` just to test hello world,
which is not part of the documentation, but I don't think that's causing the
issue. Here's the code for that if it's relevant.)

urls.py:

    
    
    from django.conf.urls import patterns, include, url
    from django.contrib import admin
    from django.views.debug import default_urlconf
    from django.http import HttpResponse
    
    def hello(request):
        return HttpResponse('Hello world!!!')
    
    urlpatterns = patterns('',
        # Examples:
        url(r'^$', hello),
        # url(r'^blog/', include('blog.urls')),
    
        #url(r'^admin/', include(admin.site.urls)),
        #url(r'^$', default_urlconf),
    )
    

Now, the issue I'm running into is when I get to the "Playing with the API"
section. When I open a `python manage.py shell` for the second time in that
section, I'm supposed to be able to use the command `Question.objects.all()`
and get the result `[<Question: What's up?>]` with "What's up?" being the
value of `question_text`. The problem is I'm still getting the result
`[<Question: Question object>]` instead of the `question_text` value.

I've gone back and re-created my app three times in the hope that I missed
something during the setup, but I get the same issue every time and I seem to
be following the documentation exactly. Am I missing something here?


Answer: First, make sure that the contents of `models.py` match with what's given in
the tutorial

    
    
    from django.db import models
    
    class Question(models.Model):
        question_text = models.CharField(max_length=200)
        pub_date = models.DateTimeField('date published')
    
        def __unicode__(self):              # __str__ on Python 3
            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, default="")
        votes = models.IntegerField(default=0)
    
        def __unicode__(self):              # __str__ on Python 3
            return self.choice_text
    

Also make sure that the migrations are up to date.

If you're running python 2, use `__unicode__` else use `__str__`.

That should solve the problem for you.

