Added Tag completion in add posts

Please redo the requirements installs!
This commit is contained in:
2020-06-07 08:35:24 +00:00
parent d27d820880
commit 1ba4b519bd
7 changed files with 98 additions and 5 deletions

View File

@@ -12,6 +12,7 @@ from django.core.cache import cache
from django.utils.text import slugify
from django.utils import timezone
from django.http import JsonResponse
def get_next_dict():
posts=Post.news_objects.order_by('-public_date').values('slug')
@@ -60,6 +61,23 @@ def slug_calc(request):
return HttpResponseServerError("Requires a title field.")
# Ajax function that returns autocomplete suggestions for a given tag input
def tag_complete(request):
if request.method == "GET":
get = request.GET.copy()
term = get['term']
tag_objects = Tag.objects.filter(name__istartswith=term)
tag_array =[]
for elem in tag_objects:
tag_array.append(elem.name)
return JsonResponse(tag_array, safe=False)
return HttpResponseServerError("Requires a term field.")
class PostViewSet(viewsets.ModelViewSet):
"""
API endpoint that allows users to be viewed or edited.