I'm not sure what you would expect icontains to do when filtering over date data, so you may want to rethink that or clarify what your are expecting.
Overall you are trying to query based on the datefield. You have 2 choices. You either need to convert your sting into a date (or datetime) object, or you need to format your string as "yyyy-mm-dd".
-- edit --
Since it looks like you're really trying to use strings to search for dates here is some sort of clarification.
What you're looking to do is going to be beyond hard to do. I'd go with borderline impossible. Django is translating your queries into SQL and querying your database. Just because the ORM is there doesn't make it able to do things not possible in SQL (in fact the ORM greatly limits what you can do). However, you have several choices:
- Write python to parse the strings and come up with date objects to match them. This may be quite difficult. You will then want to use
Q
objects from django.db.models
to construct a complex OR query. This will likely be slow when it gets to the database on any reasonable number or records.
- Figure out what the SQL would look like to generate what you're trying to do. This isn't going to be easy IMO as there is so much variance and the underlying representation of dates in your database isn't going to be a string so you're really going to be in for it. This is essentially manually doing the same thing that #1 does, except manually. Once you've constructed the SQL run a
raw
query.
- Convert to using django-haystack to use a full text search engine. This is a lot of infrastructure and has a lot of potential negatives from having to rewrite your code to anticipate search engine results. Depending on the backend you choose to plug into haystack it may be smart enough to be able to understand the strings entered and correctly search...or you may have to manually generate a ton of string representations to be in your search index so that they can be properly queried. Overall this type of thing is what full text search engines excel at because they understand language. Databases do not, they understand data and they don't get to be fuzzy.
More or less what you're asking for is quite hard. The most viable option in my opinion is to convert to using haystack. I can't emphasize enough how many drawbacks there are to that. You're dealing with search engine results instead of model instances. In some circumstances that isn't an issue, but depending on the requirements, that could be quite painful.