api zugriff für posts

This commit is contained in:
2020-05-09 15:02:35 +00:00
parent 27e23afd93
commit 1c502d7f48
5 changed files with 38 additions and 7 deletions

View File

@@ -2,8 +2,10 @@ from django.shortcuts import render
from django.http import HttpResponse
from collections import deque
from .models import Post
from .models import Post, PostSerializer
from taggit.models import Tag
from rest_framework import viewsets
from rest_framework import permissions
# Create your views here.
def index(request):
@@ -18,3 +20,13 @@ def show(request,id=None):
elif id != ""and not id is None:
p=Post.objects.get(slug=(id))
return render(request, 'posts/show.html', {"post":p})
class PostViewSet(viewsets.ModelViewSet):
"""
API endpoint that allows users to be viewed or edited.
"""
queryset = Post.objects.all().order_by('-public_date')
serializer_class = PostSerializer
permission_classes = [permissions.IsAuthenticated]
lookup_field='slug'