37 lines
928 B
Python
37 lines
928 B
Python
from django.shortcuts import get_object_or_404
|
|
from ninja import ModelSchema, Router
|
|
from .models import Rapid
|
|
|
|
from .decorators import user_is_author_or_rapid_checker
|
|
from django.core.exceptions import PermissionDenied
|
|
|
|
from ninja.security import django_auth
|
|
|
|
router = Router()
|
|
|
|
|
|
class RapidSchema(ModelSchema):
|
|
class Config:
|
|
model = Rapid
|
|
|
|
#model_fields = ["question", "history", "feedback", "normal", "laterality"]
|
|
model_fields = "__all__"
|
|
|
|
#model_exclude = ["answers"]
|
|
|
|
|
|
@router.get('/')
|
|
def list_rapids(request):
|
|
return [
|
|
{"id": e.id, "normal": e.normal}
|
|
for e in Rapid.objects.all()
|
|
]
|
|
|
|
@router.get('/question/{question_id}', response=RapidSchema)
|
|
def get_rapid_details(request, question_id: int):
|
|
print(request.user)
|
|
#if not request.user.is_superuser:
|
|
# raise PermissionDenied
|
|
|
|
rapid = get_object_or_404(Rapid, id=question_id)
|
|
return rapid |