stuck in implementing search in django
<p>I want to implement search in django. I don't use any search technique like solar etc. I am using simple filter query of django.
Now the problem is this: 
I have a model <strong><code>Product</code></strong>
with five field <code>name</code>, <code>cost</code>, <code>brand</code>, <code>expiry_date</code>, <code>weight</code>
I want to implement a advanced search feature with all fields,
by:</p>

<pre><code>name = request.GET.get('name')
</code></pre>

<p>I get a value on which basis I search all product.
What I want is that when <strong><code>name = None</code></strong>, it has to search for all names.
<strong>So problem is this: if values are not coming by user side, how can i search for all names?</strong></p>

<p>You didn't show your search query. However, I think using <a href="https://docs.djangoproject.com/en/1.10/ref/models/querysets/#contains" rel="nofollow"><code>contains</code></a> (or <a href="https://docs.djangoproject.com/en/1.10/ref/models/querysets/#icontains" rel="nofollow"><code>icontains</code></a> for case insensitive match) will help you solve the problem, with the benefit of being able to search for say first names, last names and names containing a matching text.</p>

<p>You would do:</p>

<pre><code>name = request.GET.get('name', '')
search_result = Product.objects.filter(name__icontains=name)
</code></pre>

<p>Notice the <code>get</code> method has been instructed to return a <code>''</code> instead of the default <code>None</code>. And keep in mind that all strings in Python contain the empty string <code>''</code>. So when no <code>name</code> is sent via the <code>request</code>, every <code>Product</code> in the DB (with a not <em>NULL</em> name) is returned, as their names all contain the empty string <code>''</code>.</p>

python django