Try using filter(id__regex=r'\w’) I’m not sure if this will give you the exact results your looking for, but worth a shot.
Sent from my mobile device > On Apr 26, 2018, at 2:31 AM, [email protected] wrote: > > Thank you for your help! And yes, I think I should use regex. But could you > please show me how to use it in my example, since I am new to django.. > > 在 2018年4月26日星期四 UTC+1上午2:14:10,James Farris写道: >> >> I believe you want to use icontains rather than contains. It’s case >> insensitive. >> >> I’m not sure without using regex it’s possible to return the results based >> on any character in any order in the search string. >> >>> On Apr 25, 2018, at 5:13 PM, [email protected] wrote: >>> >>> Hello everyone! >>> >>> Currently I am working on Django. >>> >>> I defined a 'Search' function in views.py: >>> >>> def search(request): >>> q = request.GET.get("q") >>> if q: >>> ReactResul = Reactionsmeta.objects.filter(id__contains=q) >>> MetaResul = Metabolites.objects.filter(id__contains=q) >>> GeneResul = Genes.objects.filter(id__contains=q) >>> >>> else: >>> # you may want to return Customer.objects.none() instead >>> ReactResul= Reactionsmeta.objects.all() >>> GeneResul = Genes.objects.all() >>> MetaResul = Metabolites.objects.all() >>> context = dict(result_1=MetaResul, q=q, result_2=ReactResul, result_3 = >>> GeneResul) >>> return render(request, "Recon/search.html", context) >>> >>> And now I want to make it more powerful. >>> >>> If I want to search '10FTH86RSK' but I cannot remember the whole name, I >>> can just use part of the string to make query. For example, if I type >>> '10FTK', '10FTH86RSK' should be returned as result. >>> In that case, '10FTK', '10F6TK' or '10FTK4' should also be returned as >>> results. >>> >>> So how could I achieve this function? >>> -- >>> 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 [email protected]. >>> To post to this group, send email to [email protected]. >>> Visit this group at https://groups.google.com/group/django-users. >>> To view this discussion on the web visit >>> https://groups.google.com/d/msgid/django-users/793b8999-cac4-4c2d-94cc-eabb80f4e702%40googlegroups.com. >>> 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 [email protected]. > To post to this group, send email to [email protected]. > Visit this group at https://groups.google.com/group/django-users. > To view this discussion on the web visit > https://groups.google.com/d/msgid/django-users/75275cd3-84d0-45fb-a104-4cc5c224f813%40googlegroups.com. > 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 [email protected]. To post to this group, send email to [email protected]. Visit this group at https://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/9F2E0677-FD8C-446B-83DA-8119D6D3705C%40gmail.com. For more options, visit https://groups.google.com/d/optout.

