Skip to content

Commit

Permalink
Make test API for attendants
Browse files Browse the repository at this point in the history
  • Loading branch information
HollowKaeden committed Nov 12, 2024
1 parent 3bb6852 commit 1d0e88b
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 1 deletion.
13 changes: 12 additions & 1 deletion serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,18 @@
from .models import Attendant


# This is a serializer for the nfc_id field
class BinaryFieldSerializer(serializers.Field):
def to_representation(self, value):
return value.hex()

def to_internal_value(self, data):
return bytes.fromhex(data)


class AttendantSerializer(serializers.HyperlinkedModelSerializer):
nfc_id = BinaryFieldSerializer()

class Meta:
model = Attendant
fields = '__all__'
fields = "__all__"
14 changes: 14 additions & 0 deletions urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from django.contrib import admin
from django.urls import path, include
from . import views
from rest_framework import routers


# router for attendant urls
router = routers.DefaultRouter()
router.register(r"attendants", views.AttendantViewSet)


urlpatterns = [
path("", include(router.urls)),
]
8 changes: 8 additions & 0 deletions views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from rest_framework import viewsets
from database.serializers import AttendantSerializer
from database.models import Attendant


class AttendantViewSet(viewsets.ModelViewSet):
queryset = Attendant.objects.all()
serializer_class = AttendantSerializer

0 comments on commit 1d0e88b

Please sign in to comment.