add search for all model names
This commit is contained in:
@ -22,7 +22,7 @@ from lazysignup.views import convert
|
|||||||
from dashboard.views import dashboard
|
from dashboard.views import dashboard
|
||||||
from cataloglist.views import cataloglist, my_catalogs, public_catalogs
|
from cataloglist.views import cataloglist, my_catalogs, public_catalogs
|
||||||
from catalogedit.views import catalogedit, get_catalog, save_catalog
|
from catalogedit.views import catalogedit, get_catalog, save_catalog
|
||||||
from products.views import search_products
|
from products.views import search_products, all_models
|
||||||
|
|
||||||
from .forms import UserCreationForm
|
from .forms import UserCreationForm
|
||||||
from .views import login_guest, lazy_convert_done
|
from .views import login_guest, lazy_convert_done
|
||||||
@ -43,6 +43,7 @@ urlpatterns = [
|
|||||||
path('api/v1/catalogs/save', save_catalog, name='save_catalog'),
|
path('api/v1/catalogs/save', save_catalog, name='save_catalog'),
|
||||||
|
|
||||||
path('api/v1/products/search', search_products, name='search_products'),
|
path('api/v1/products/search', search_products, name='search_products'),
|
||||||
|
path('api/v1/products/models', all_models, name='all_models'),
|
||||||
|
|
||||||
path('admin/', admin.site.urls),
|
path('admin/', admin.site.urls),
|
||||||
path("account/", include("account.urls")),
|
path("account/", include("account.urls")),
|
||||||
|
|||||||
@ -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.csrf import csrf_exempt
|
||||||
from django.views.decorators.http import require_http_methods
|
from django.views.decorators.http import require_http_methods
|
||||||
from django.db import connections
|
from django.db import connections
|
||||||
|
from django.db.models import Count
|
||||||
|
|
||||||
import json
|
import json
|
||||||
import logging
|
import logging
|
||||||
@ -117,3 +118,35 @@ def search_products(request):
|
|||||||
}
|
}
|
||||||
|
|
||||||
return JsonResponse(out)
|
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)
|
||||||
|
|||||||
Reference in New Issue
Block a user