Answer the question
In order to leave comments, you need to log in
How to filter by substring of model records?
I am making a search engine based on the vedModel model. I need that when entering a substring, for example, an account, I get all the record options from the vedModel model with a title (topic field), that is, for example, a textbook and a notebook, students at their desks, school supplies - these are textbooks, etc.
vedModel
class vedModel(models.Model):
topic = models.CharField('Тема', max_length = 100, null = True, )
# категория, подкатегория
category = models.CharField('Категория', max_length = 40, null = True, blank = True, )
sub_category = models.CharField('Подкатегория', max_length = 40, null = True, blank = True, )
from django.http import JsonResponse#, HttpResponse
# статьи
from ved.models.article import vedModel
# вернт рекламные баннеры
def ajax_searchDef(request):
if request.method == 'GET':
# текст поискового запроса
search = request.GET['search']
res_list = []
# тут должна быть фильтрация по подстроке
return JsonResponse({'res_list': res_list, })
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question