add search for all model names

This commit is contained in:
2020-01-14 12:41:37 -08:00
parent fd21c1c6b3
commit 5e1d6db078
2 changed files with 35 additions and 1 deletions

View File

@ -3,6 +3,7 @@ from django.shortcuts import render, get_object_or_404
from django.views.decorators.csrf import csrf_exempt
from django.views.decorators.http import require_http_methods
from django.db import connections
from django.db.models import Count
import json
import logging
@ -117,3 +118,35 @@ def search_products(request):
}
return JsonResponse(out)
@csrf_exempt
@login_required
@require_http_methods(["GET"])
def all_models(request):
# TODO ignoring for now
# body = request.body
# if not body or len(body) < 1:
# return HttpResponse('Bad request: no data', status=400)
# data = json.loads(body.decode('utf-8'))
# season_id = data.get('season')
# if not season_id or len(season_id) < 1:
# return HttpResponse('Bad request: no season id', status=400)
# season = Season.objects.get(id=season_id)
# if not season:
# return HttpResponse('Bad request: no season found', status=400)
# region_id = data.get('region')
# if not region_id or len(region_id) < 1:
# return HttpResponse('Bad request: no region id', status=400)
# region = Region.objects.get(id=region_id)
# if not region:
# return HttpResponse('Bad request: no region found', status=400)
models = Product.objects.all().values('name').annotate(total=Count('id')).order_by('name')
log.debug('loaded %s model names', len(models))
return JsonResponse(list(models), safe=False)