《千锋Django培训》网课笔记(从18到)
程序员文章站
2024-01-28 16:54:16
...
十八.
验证阶段:
首先,我们先通过python3 manage.py shell进入shell模式,并测试一下,当我们自定义模型管理器前,objects的情况
>>> from myApp.models import Grades, Students
>>> from django.utils import timezone
>>> from datetime import *
>>> Grades.objects.all()
<QuerySet [<Grades: python04>, <Grades: python05>, <Grades: python06>, <Grades: python07>]>
>>> Grades.objects.values()
<QuerySet [{'id': 1, 'gname': 'python04', 'gdate': datetime.datetime(2017, 7, 17, 0, 0, tzinfo=<UTC>), 'ggirlnum': 3, 'gboynum': 70, 'isDelete': False}, {'id': 2, 'gname': 'python05', 'gdate': datetime.datetime(2017, 7, 31, 0, 0, tzinfo=<UTC>), 'ggirlnum': 1, 'gboynum': 99, 'isDelete': False}, {'id': 3, 'gname': 'python06', 'gdate': datetime.datetime(2018, 9, 3, 15, 23, tzinfo=<UTC>), 'ggirlnum': 34, 'gboynum': 56, 'isDelete': False}, {'id': 5, 'gname': 'python07', 'gdate': datetime.datetime(2018, 9, 3, 15, 41, tzinfo=<UTC>), 'ggirlnum': 12, 'gboynum': 23, 'isDelete': False}]>
>>> Students.objects.all()
<QuerySet [<Students: Invoker>, <Students: phantom assassin>, <Students: Wraith King>, <Students: bristle>, <Students: omniknight>, <Students: Spectre>, <Students: Cristal Maiden>]>
>>> Students.objects.values()
<QuerySet [{'id': 1, 'sname': 'Invoker', 'sgender': True, 'sage': 80, 'scontend': 'hello,physcis', 'isDelete': False, 'sgrade_id': 1}, {'id': 2, 'sname': 'phantom assassin', 'sgender': True, 'sage': 50, 'scontend': 'hi', 'isDelete': False, 'sgrade_id': 1}, {'id': 3, 'sname': 'Wraith King', 'sgender': True, 'sage': 45, 'scontend': 'hi', 'isDelete': False, 'sgrade_id': 1}, {'id': 4, 'sname': 'bristle', 'sgender': True, 'sage': 23, 'scontend': "i'm bristle", 'isDelete': True, 'sgrade_id': 5}, {'id': 5, 'sname': 'omniknight', 'sgender': False, 'sage': 18, 'scontend': "i'm omniknight", 'isDelete': True, 'sgrade_id': 5}, {'id': 6, 'sname': 'Spectre', 'sgender': True, 'sage': 35, 'scontend': "i'm Spectre", 'isDelete': False, 'sgrade_id': 3}, {'id': 7, 'sname': 'Cristal Maiden', 'sgender': False, 'sage': 18, 'scontend': 'Queen of Ice', 'isDelete': False, 'sgrade_id': 2}]>
十九.
二十.