models.py
from django.db import models class Person(models.Model): name=models.CharField(max_length=30) age=models.IntegerField() def __unicode__(self): return self.name
./manage.py shell
Person.objects.order_by("id")
[<Person: lanny>, <Person: mxl>, <Person: wang>, <Person: zhang>, <Person: zhao>, <Person: li>]
#切片打印出列表
Person.objects.order_by("id")[:1] [<Person: lanny>] Person.objects.order_by("id")[:2] [<Person: lanny>, <Person: mxl>]
#倒序排列
Person.objects.order_by("-id")[:2] [<Person: li>, <Person: zhao>] Person.objects.all() [<Person: lanny>, <Person: mxl>, <Person: wang>, <Person: zhang>, <Person: zhao>, <Person: li>]
创建、查询
Person.objects.create(name=lanny,age=23) Person.objects.get(name="lanny")
时间: 2024-10-10 07:55:22