I just started using Django, and I am going through the documentation here 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:
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?
Aucun commentaire:
Enregistrer un commentaire