2017-09-13 56 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')