Django 数据库查询方法一

birthday__year=2006 

headline__startswith='What' 等价于 headline__startswith like 'What%'

headline__endswith='What' 等价于 headline__startswith like '%What'

birthday__gte=datetime.now() 等价于 birthday__gte >= datetime.now()

birthday__lte=datetime.now() 等价于 birthday__gte <= datetime.now()

pk__gt=14 等价于 pk>14

name__icontains="food" 等价于 name like "%food%"

headline__exact="Man bites dog" 等价于 headline = 'Man bites dog';

name__iexact="beatles blog" 查找name="beatles blog"的对象,不区分大小写

name__isnull=True 查询的是name为null的值

pk__in=[1,4,7] 等价于 id in{1,4,7} 

 

一对多

many端

e = Entry.objects.get(id=2) 

print e.blog

 

one端

b = Blog.objects.get(id=1)

b.entry_set.all()

b.entry_set.count()

 

源:http://www.cnblogs.com/linjiqin/p/3623541.html

你可能感兴趣的:(django)