- Django 2 by Example
- Antonio Melé
- 37字
- 2021-06-25 21:19:01
Using exclude()
You can exclude certain results from your QuerySet using the exclude() method of the manager. For example, we can retrieve all posts published in 2017 whose titles don't start with Why:
Post.objects.filter(publish__year=2017) \
.exclude(title__startswith='Why')