Django filter vs get in models

后端 未结 4 1707
隐瞒了意图╮
隐瞒了意图╮ 2021-01-12 04:06

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)
<
4条回答
  •  没有蜡笔的小新
    2021-01-12 04:45

    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)
    

提交回复
热议问题