I am trying to implement the functionality of a search bar.
my models.py:
class Question(models.Model):
questionId = models.IntegerField(primary_key=True)
groupId = models.IntegerField(default=0)
questionTitle = models.TextField()
groupName = models.CharField(max_length=500, null=True, blank=True)
correctAnsRef = models.ManyToManyField(CorrectAns, related_name="questionReletedResponses")
My database is huge, so I tried to skip Question.objects.all() to save time.
my views.py:
def questionList(request)
# Searching Any Value
if request.method == "POST" and request.POST['searchKey'] != '':
searchKey = request.POST['searchKey']
questions = Question.objects.filter(questionId=searchKey)
return render(request,'diagnosis/questionList.html', {'questions': questions})
This works perfectly but it can only filter by questionId. I wish to have such a search bar that will filter by matching all the fields(questionId, groupId, questionTitle... etc all) the Question model has. (note: request.GET already been used for pagination.)
Please suggest how can I do this?