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
conclusion