At least when I tested a similar query it makes an OUTER JOIN, not an INNER
JOIN

What's the actual SQL command being executed?

print Shops.objects.filter(...).query



On Wed, Mar 11, 2015 at 1:19 PM, Ajay M <aja...@triassicsolutions.com>
wrote:

> Hi Vijay,
> The search text is okay.. I think when  using the state__state_name and
> city__city_name relations Django INNER JOIN removes the shop without
> existing relation from the result.
>
>    On Wednesday, March 11, 2015 at 8:22:55 PM UTC+5:30, Vijay Khemlani
> wrote:
>>
>> At least when using Postgres that query makes a LEFT OUTER JOIN so it
>> shouldn't discard Shops just because they don't have a state or city.
>>
>> So your query seems to be OK
>>
>> are you sure your search text is fine? the orm will not automatically
>> strip the search_text into a list of keywords or things like that. For
>> example, searching for "ski shop" will not match a Shop with name "ski
>> super shop".
>>
>> On Wed, Mar 11, 2015 at 11:30 AM, Ajay M <aja...@triassicsolutions.com>
>> wrote:
>>
>>> Hi I'm a newbie to Django. I'm trying to implement a search feature like
>>> this.
>>>
>>> query_results = Shops.objects.filter\
>>>                             (Q(shop_name__icontains=search_text)\
>>>                             |Q(state__state_name__icontains=search_text)\
>>>                             
>>> |Q(city__city_name__icontains=search_text)).distinct()
>>>
>>> I would like to search Shops based on the shop_name, state_name and
>>> city_name. State and city fields are foreign keys. For some 'Shops'
>>> stateandcity are null. However, shop_name contains the search_text. So
>>> I'm not getting those 'Shops' by running this query. Any help on this
>>> is appreciated.
>>>
>>> --
>>> You received this message because you are subscribed to the Google
>>> Groups "Django users" group.
>>> To unsubscribe from this group and stop receiving emails from it, send
>>> an email to django-users...@googlegroups.com.
>>> To post to this group, send email to django...@googlegroups.com.
>>> Visit this group at http://groups.google.com/group/django-users.
>>> To view this discussion on the web visit https://groups.google.com/d/
>>> msgid/django-users/0c156715-b2fb-46ab-ad3d-d25235e7c4ca%
>>> 40googlegroups.com
>>> <https://groups.google.com/d/msgid/django-users/0c156715-b2fb-46ab-ad3d-d25235e7c4ca%40googlegroups.com?utm_medium=email&utm_source=footer>
>>> .
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>
>>  --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/a312dafe-8def-47fd-89a7-33bec42c5ba3%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/a312dafe-8def-47fd-89a7-33bec42c5ba3%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CALn3ei2sdJbruwhA_oJkpj_TTkunnW6yjQ29yOUYGZS6a3c0WQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to