根据model类升级数据库指令

python manage.py makemigrations polls
python manage.py migrate

shell命令行模式

python manage.py shell
from polls.models import Choice, Question
Question.objects.all()
from django.utils import timezone
q = Question(question_text="What's new?", pub_date=timezone.now())
q.save()
Question.objects.filter(id=1)
Question.objects.filter(question_text__startswith='What')
Question.objects.get(pub_date__year=current_year)
q.choice_set.all()
q.choice_set.create(choice_text='Not much', votes=0)
q.choice_set.count()
c.delete()
python manage.py createsuperuser

Exception

# For get(), This exception is an attribute of the model class that the query is being performed on 
DoesNotExist
MultipleObjectsReturned

lookuptype

lte
gte
lt
gt
iexact
contains
icontains
startswith, endswith
istartswith, iendswith

aggregate() is a terminal clause for a QuerySet that, when invoked, returns a dictionary of name-value pairs. The name is an identifier for the aggregate value; the value is the computed aggregate. The name is automatically generated from the name of the field and the aggregate function. If you want to manually specify a name for the aggregate value, you can do so by providing that name when you specify the aggregate clause

>>> Book.objects.aggregate(average_price=Avg('price'))
{'average_price': 34.35}

inspect the SQL with str(queryset.query) and write plenty of tests.