标签:django shell
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")
本文出自 “LannyMa” 博客,请务必保留此出处http://lannyma.blog.51cto.com/4544390/1736104
标签:django shell
原文地址:http://lannyma.blog.51cto.com/4544390/1736104