I am learning django and I am currently working on a blog project. I have a basic search function which filters the posts accordingly. It works fine by searching for content in my title and content filters of the posts. I am trying to add a new filter so that I can type in the month for example "March" and then it will filter out all the posts that were published in March. All the models of Post(just a normal post in a blog) has this:
models.py
class Post(models.Model):
title = models.CharField(max_length=120)
content = models.TextField()
publish = models.DateField(auto_now=False, auto_now_add=False)
And in my views.py I have the following search function: (only the relevant stuff)
views.py
queryset_list = Post.objects.all()
query = request.GET.get("q")
if query:
queryset_list = queryset_list.filter(
Q(title__icontains=query) |
Q(content__icontains=query) |
Q(publish__icontains=query)
).distinct()
In the template the publish attribute is displayed like this: "July 12, 2016" if the publish date is set to 2016-07-12.
Like I mentioned the search function filters the posts fine when the title or content is = to the query, but it does not work if I search for "July". Then it doesn't return any posts.
I would like to know what I can do so it can filter the posts by the publish date as well.