Django - Getting last object created, simultaneous filters

后端 未结 7 2132
花落未央
花落未央 2020-12-24 00:39

Apologies, I am completely new to Django and Python.

I have 2 questions. First, how would I go about getting the last object created (or highest pk) in a list of obj

7条回答
  •  盖世英雄少女心
    2020-12-24 01:23

    For the largest primary key, try this:

    List.objects.order_by('-pk')[0]
    

    Note that using pk works regardless of the actual name of the field defined as your primary key.

提交回复
热议问题