-1👍
A good starting point could be using Django REST Framework ModelViewSet
and ModelSerializer
:
# serializers.py
class AnimalSerializer(serializers.ModelSerializer):
class Meta:
model = Animals
fields = '__all__'
# views.py
class AnimalViewSet(ModelViewSet):
queryset = Animals.objects.all()
serializer = AnimalSerializer
# urls
router = DefaultRouter()
router.register(r'animals', AnimalViewSet, base_name='animal')
urlpatterns = [router.urls]
Around that, you could add validation logic in your serializer, permission_classes
in your viewset, …etc.
Source:stackexchange.com