Single-table queries will be 13

Must know will be 13

Before the operation following the operation, we realized created a data table, where the main demonstration of the following operations are no longer prepared to go into detail creation process

<1> all (): Query all results

<2> filter (** kwargs): it contains the object and filters that match a given

<3> get (** kwargs): returns the object with the given filter criteria matches one and only one result is returned, if the object matching the filter will throw more than one or no errors.

<4> exclude (** kwargs): it contains the object and filters that do not match the given conditions

<5> values ​​(* field): Returns a ValueQuerySet-- QuerySet that a special, not obtained after running a series of instantiating an object model, but an iterative sequence dictionaries

<6> values_list (* field): it values ​​() are very similar, it returns a tuple sequence, return values ​​is a sequence of dictionary

<7> order_by (* field) : sort query results

<8> reverse (): Reverse sort query results, note the reverse () usually only have to call on the QuerySet defined sequence (Meta model class in specified in ordering or call order_by () method).

<9> distinct (): eliminate duplicate records (if you query across multiple tables, may be obtained from the returned results in the calculation of QuerySet reproducible results can now use distinct (), note that only supported by fields go in PostgreSQL. weight).

<10> COUNT (): returns the match query database (QuerySet that) the number of objects.

<11> first (): returns the first record

<12> last(): 返回最后一条记录

<13> exists(): 如果QuerySet包含数据,就返回True,否则返回False

13个必会操作总结

返回QuerySet对象的方法有

all()

filter()

exclude()

order_by()

reverse()

distinct()

特殊的QuerySet

values()       返回一个可迭代的字典序列

values_list() 返回一个可迭代的元祖序列

返回具体对象的

get()

first()

last()

返回布尔值的方法有:

exists()

返回数字的方法有

count()

Guess you like

Origin www.cnblogs.com/wangnanfei/p/11545283.html