1

I know i could use __in on a list like but what about something like python's:

# might not be able to separate on whitespace
'abc' in 'this_is a stringwith_abc+in it'  

except I do not want to split the string into a list because I can't be sure of the character on which to split.

So something like:

Model.objects.filter(charfield__in='blob of text to find field value within')

edit1:

__contained is not what I am looking for, if anything a __contained_by method would be the solution

Verbal_Kint
  • 1,366
  • 3
  • 19
  • 35
  • I'm not sure how you would achieve this with Djano's QuerySet syntax, but at first glance it seems like any query like this will require a full table scan. Even with a linear time search on the text blob, you'll have to search ever row in your table. – Keyan P Jul 05 '16 at 01:59
  • Possible duplicate of [sql "LIKE" equivalent in django query](http://stackoverflow.com/questions/18140838/sql-like-equivalent-in-django-query) – e4c5 Jul 05 '16 at 02:05
  • @KeyanP Even if it was one of many kwargs or multiple appended `.filter()` methods? – Verbal_Kint Jul 05 '16 at 02:14
  • Your question isn't still very clear. Given a constant string S, Is it that for each row X in the table, you want to know S contains X ? – e4c5 Jul 05 '16 at 03:54
  • @e4c5 I would like to find if a sub-string (model field) is present within another string (constant). So to try and match your example: Given a constant string S, for each column X in the table, I want to know if X contains S. – Verbal_Kint Jul 09 '16 at 04:40
  • @e4c5 the best comparison I can currently think of is the `__contained_by` query for lists except for a string – Verbal_Kint Aug 03 '16 at 17:36

0 Answers0