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

Popular posts from this blog

Messages Framework in Django

Forms in Django(bound, unbound, clean, is_valid, errors)

Advantages to using URLField() over TextField()