Skip to content

Commit

Permalink
History API to get all entries related to an object by its UUID
Browse files Browse the repository at this point in the history
  • Loading branch information
jmr committed Apr 16, 2021
1 parent f3160c0 commit 0215718
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 0 deletions.
Empty file added api/__init__.py
Empty file.
17 changes: 17 additions & 0 deletions api/serializers.py
@@ -0,0 +1,17 @@
from rest_framework import serializers

from history.models import HistoryEntry

__all__ = [
"HistoryEntryListSerializer",
]


class HistoryEntryListSerializer(serializers.ModelSerializer):
class Meta:
model = HistoryEntry
fields = [
"object_uuid",
"message",
"created",
]
8 changes: 8 additions & 0 deletions api/urls_v1.py
@@ -0,0 +1,8 @@
from django.urls import path

from history.api.views import HistoryEntryListAPIView

app_name = "history_api_v1"
urlpatterns = [
path("<uuid:uuid>/", HistoryEntryListAPIView.as_view(), name="history-list"),
]
18 changes: 18 additions & 0 deletions api/views.py
@@ -0,0 +1,18 @@
from rest_framework.authentication import SessionAuthentication
from rest_framework.generics import ListAPIView

from history.api.serializers import HistoryEntryListSerializer
from history.models import HistoryEntry

__all__ = [
"HistoryEntryListAPIView",
]


class HistoryEntryListAPIView(ListAPIView):
serializer_class = HistoryEntryListSerializer
authentication_classes = [SessionAuthentication, ]

def get_queryset(self):
"""Filter the queryset with the object's uuid passed in url"""
return HistoryEntry.objects.filter(object_uuid=self.kwargs["uuid"])

0 comments on commit 0215718

Please sign in to comment.