コード例 #1
0
ファイル: sample.py プロジェクト: cps847-group6/A3
 
# Save the object into the database. You have to call save() explicitly.
q.save()
q3.save()

#id is auto-assigned
q.id

# Access model field values via Python attributes.
q.question_text
q.pub_date
 
# Change values by changing the attributes, then calling save().
q.question_text = "What's up?"
q.save()
q3.owner_id = "Question 3 User"
q3.save()
 
# objects.all() displays all the questions in the database.
Question.objects.all()


# Django provides a rich database lookup API that's entirely driven by
# keyword arguments.
Question.objects.filter(id=1)

Question.objects.filter(question_text__startswith='What')


# Request an ID that doesn't exist, this will raise an exception.
Question.objects.get(id=3)