2017-09-13 47 views
-2

我在db中有一个字段,其中包含“Food,Financial,Health”字符串。我需要在该字段中搜索以“Fi”开头的字符串。我可以使用包含搜索字符串,但我需要在django查询中搜索startswith。任何人都建议我这样做。在数据库列中查找字符串django查询

+0

你应该先搜索,这是第一个搜索结果如果搜索的Django查询https://开头的文档.djangoproject.com/en/1.11/topics/db/queries /#chaining-filters – Gahan

+0

[Django startswith query]的可能重复(https://stackoverflow.com/questions/14740446/django-startswith-query) – Serjik

回答

0

您可以使用Django的查询startswith ..

SomeModel.objects.filter(stringField__startswith='What')