Say, I have a model with a text field:
class SomeModel
keyword=models.CharField(null=True, max_length=255)
Now, I know how to check if a parameter string (lets call the variable "querystring" is contained in the field keyword:
results = SomeModel.objects.filter(keyword_icontains=querystring).all()
which I found in the django docs
Question, how do I filter for the objects whose field values are contained in the querystring variable?
Apologies if my question is confusing... maybe an example will clarify...
In django docs, if my keyword field contains,for example, 'python-django', then, for a querystring that contains 'django', I can extract the object that contains that field with an
results=SomeModel.objects.filter(keyword_icontains=querystring).all()
or results=SomeModel.objets.filter(keyword_icontains='django').all()
But say, I want to extract all rows/objects whose keyword field is contained in a querystring? For example, if querystring contains 'In django, how do I create a filter'? then I want results to contain all objects whose keyword fields have the values 'django', 'filter', etc...
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…