Django filter vs get in models

后端 未结 4 1686
隐瞒了意图╮
隐瞒了意图╮ 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:55

    Basically use get when you want to get a single unique object, and filter when you want to get all objects that match your lookup parameters

     __data = User.objects.get(is_active=1).exclude(id=id)
    

    Error:get() returned more than one User -- it returned 19!, Type:

    ------successful-------

    __data = User.objects.filter(is_active=1).exclude(id=id)
    

    -------successful------

    Check the Link

提交回复
热议问题