In the search form field, If I don't enter anything, but push on the button to search the query. The query returns every each field from the database. Company.objects.exclude(Q(name__isnull=True)).exclude(Q(name__exact='')) Somehow, doesn't help me. If I use them together or separate. The code in views.py is:
class className(listView)
model=Company
template_name='name_of_the_template.html'
def get_queryset(self):
query=self.request.Get.get('q')
query=query.replace('#',' ') //same for ?\/$%^+*()[] *tried to set exclude code here
if query == ' ':
object_list = Company.objects.filter(Q(name__icontains='None'))//sending to the empty object
return object_list
else:
// *tried to set exclude code here
object_list = Company.objects.filter(Q(name__icontains=query))
return object_list
None of exclude code helps. I believe I do simple mistake somewhere... because code suppose to work, but somehow still. I just also tried to get rid off if else statement and use exclude statements for queries such as '', ' ' and null and after that filter for query... And now excluding queries for ' ' also doesn't work...
Django doesn't tell me the exclude doesn't work, all works, except, it is like not in the code.