简体   繁体   中英

How to search CharField in Django?

I want to do a search feature: I use GodX to register my username in user management after I search godx as username keyword, I can get the GodX object.

Currently I am limited to do the following:

from django.contrib.auth.models import User

user = user.objects.get(username="godx")
# I hope I can get `GodX` object but the method is unavailable.

How do I do?

I find answer by myself!

According to these links from django document:

Field lookups

iexact

If I use iexact :

>>> Blog.objects.get(name__iexact="beatles blog")

It would match a Blog titled "Beatles Blog", "beatles blog", or even "BeAtlES blOG".

And the SQL equivalents:

SELECT ... WHERE name ILIKE 'beatles blog';

So, I can get I expect.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM