I'm trying the tutorial given on Django site. When I'm trying to run below command I'm getting error.
q = Question.objects.get(pk=1)
q.choice_set.all()
Traceback (most recent call last):
File "<input>", line 1, in <module>
File "C:\Python27\lib\site-packages\django\db\models\manager.py", line 228, in all
return self.get_queryset()
File "C:\Python27\lib\site-packages\django\db\models\fields\related.py", line 706, in get_queryset
qs = qs.filter(**self.core_filters)
File "C:\Python27\lib\site-packages\django\db\models\query.py", line 679, in filter
return self._filter_or_exclude(False, *args, **kwargs)
File "C:\Python27\lib\site-packages\django\db\models\query.py", line 697, in _filter_or_exclude
clone.query.add_q(Q(*args, **kwargs))
File "C:\Python27\lib\site-packages\django\db\models\sql\query.py", line 1304, in add_q
clause, require_inner = self._add_q(where_part, self.used_aliases)
File "C:\Python27\lib\site-packages\django\db\models\sql\query.py", line 1332, in _add_q
allow_joins=allow_joins, split_subq=split_subq,
File "C:\Python27\lib\site-packages\django\db\models\sql\query.py", line 1144, in build_filter
lookups, parts, reffed_aggregate = self.solve_lookup_type(arg)
File "C:\Python27\lib\site-packages\django\db\models\sql\query.py", line 1030, in solve_lookup_type
_, field, _, lookup_parts = self.names_to_path(lookup_splitted, self.get_meta())
File "C:\Python27\lib\site-packages\django\db\models\sql\query.py", line 1367, in names_to_path
if field.is_relation and not field.related_model:
File "C:\Python27\lib\site-packages\django\utils\functional.py", line 60, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "C:\Python27\lib\site-packages\django\db\models\fields\related.py", line 110, in related_model
apps.check_models_ready()
File "C:\Python27\lib\site-packages\django\apps\registry.py", line 131, in check_models_ready
raise AppRegistryNotReady("Models aren't loaded yet.")
AppRegistryNotReady: Models aren't loaded yet.
This is my models.py
from django.db import models
from django.utils import timezone
import datetime
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): # __unicode__ on Python 2
return u'%s'%self.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): # __unicode__ on Python 2
return u'%s'%self.question_text
This is my manage.py code
#!/usr/bin/env python
import os
import sys
if __name__ == "__main__":
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "demo.settings")
from django.core.management import execute_from_command_line
execute_from_command_line(sys.argv)
This is my wsgi file
"""
WSGI config for demo project.
It exposes the WSGI callable as a module-level variable named ``application``.
For more information on this file, see
https://docs.djangoproject.com/en/1.8/howto/deployment/wsgi/
"""
import os
from django.core.wsgi import get_wsgi_application
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "demo.settings")
application = get_wsgi_application()
I'm not sure what I'm doing wrong over here. I followed the tutorial, but it is breaking over here.
I'm using python 2.7.9 and Django 1.8.2