Introduction to the differences between Django objects objects.get of and objects filter of

  • 2020-06-03 07:17:29
  • OfStack

preface

Django objects. all(), objects. get() and objects. filter().

The sample code


ret=UserInfo.objects.all()

all returns the QuerySet object. The program does not actually execute the SQL statement in the database to query the data, but it does support iteration, using the for loop to retrieve the data.


ret=UserInfo.objects.get(id='1')

get returns an Model object of type list, indicating that using the get method will directly execute the sql statement to get the data


ret=UserInfo.objects.filter()

filter is similar to get, but supports more powerful queries

Supplement:

When querySet is chosen conditionally, filter means = and exclude means! =.

querySet.distinct() To repeat

___, 45en to like 'aaa' ___, 48en is exactly equal to omit case, ilike 'aaa' ___ 52en '%aaa%' ___ 54en contains ilike '%aaa%', ignoring the case, but contains has the same effect as icontains for sqlite. __gt is greater than the ___ __lt less than ___ ___ 64EN exists within the scope of 1 list __startswith to... At the beginning __istartswith to... Ignore case at the beginning __endswith to... At the end __iendswith to... Closing, ignore case __range in... Within the scope of ___ the year of the day field ___, the month of the day field ___ the day of the date field __isnull=True/False

conclusion


Related articles: