Django过滤器和模型 [英] Django filter vs get in models

查看:130
本文介绍了Django过滤器和模型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


$ b

获取

  Entry.objects.get(id__exact = 14)

过滤

  Entry.objects.filter(id__exact = 14)

上述声明有什么区别?



提前感谢

解决方案

get 只带一个等于你想要的元素,但$ 过滤器带来与您想要的项目相关的所有内容。



过滤器返回很多找到的东西。
只返回一件你要找的东西



,例如:



GET

  Task.objects.get(id = 1,status = 1)
/ pre>

过滤器

  Groups.objects.filter(user = 1)


Im a newbie to Django and would like to understand what is the difference between filter vs get

Get

Entry.objects.get(id__exact=14)

Filter

Entry.objects.filter(id__exact=14)

What difference the above statement makes?

Thanks in advance.

解决方案

the get only brings an element that is equal to what you're looking for but the filter brings everything related to that item you want.

filter returns many things found. get returns only one thing to what you're looking for

for example:

GET

Task.objects.get(id=1,status=1)

Filter

Groups.objects.filter(user=1)

这篇关于Django过滤器和模型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆