I have a model that has a MULTISELECTFIELD where the user can select which states relate to them. It uses django-localflavor in the backend and so on the form they choose 'TEXAS' and 'TX' is stored on the database. I'm using this Q query to find the users that are associated with a state. Q(states__icontains=query)
But this only returns a success for 'TX' and not 'TEXAS'. That makes sense since that is how it is stored in the database, but how can I search by Texas and get the same return?
All I can think of is to go to the Class Manager (myclassManager(models.Manager
) and create a get_state_name
method that takes in a 2 digit code and returns the state name. If that is the case, I have to make a dictionary with the list by hand.
I feel like the could be a cleaner way.
Thoughts?
I just took a look at localflavor and similar to what I suggested in my comment is built in.