L
L
lolo_to2020-09-21 16:25:47
Django
lolo_to, 2020-09-21 16:25:47

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, )


view
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

1 answer(s)
D
Dr. Bacon, 2020-09-21
@lolo_to

Question about the ability to read docs https://docs.djangoproject.com/en/3.1/ref/models/q...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question