filter() method in Django
Use the filter() method to filter a QuerySet. For Ex:, you can retrieve all posts created in the year 2019 using the following QuerySet:
>> Posts.objects.filter(publish__year=2019)
You can also filter by multiple fields. For Ex:, you can retrieve all posts published in 2019 by the author with the username abcd:
>>> Posts.objects.filter(publish__year=2019, author__username='abcd')
Comments
Post a Comment