Coverage for posts/views.py: 100.00%

25 statements  

« prev     ^ index     » next       coverage.py v7.9.1, created at 2025-06-24 10:40 -0700

1from django.contrib.auth import get_user_model 1a

2from django.views.generic import ListView 1a

3from rest_framework import generics 1a

4 

5from .models import Post 1a

6from .permissions import IsAuthorOrReadOnly 1a

7from .serializers import PostSerializer, UserSerializer 1a

8 

9 

10class PostList(generics.ListCreateAPIView): 1a

11 """ """ 

12 

13 """ 1a

14 Display a list of :model:`posts.Post` 

15 

16 **Context** 

17 

18 ``Post`` 

19 An instance of :model:`posts.Post` 

20 

21 **Template:** 

22 

23 :template:`posts/post_list.html` 

24 """ 

25 

26 permission_classes = (IsAuthorOrReadOnly,) 1a

27 queryset = Post.objects.all() 1a

28 serializer_class = PostSerializer 1a

29 

30 

31class PostDetail(generics.RetrieveUpdateDestroyAPIView): 1a

32 permission_classes = (IsAuthorOrReadOnly,) 1a

33 queryset = Post.objects.all() 1a

34 serializer_class = PostSerializer 1a

35 

36 

37class UserList(generics.ListCreateAPIView): 1a

38 queryset = get_user_model().objects.all() 1a

39 serializer_class = UserSerializer 1a

40 

41 

42class UserDetail(generics.RetrieveUpdateDestroyAPIView): 1a

43 queryset = get_user_model().objects.all() 1a

44 serializer_class = UserSerializer 1a

45 

46 

47class PostListView(ListView): 1a

48 model = Post 1a

49 template_name = "posts/post_list.html" 1a

50 

51 paginate_by = 5 1a