Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Quiz API List #9

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file.
16 changes: 16 additions & 0 deletions django_school/classroom/api/quiz.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Django

# Rest framework
from rest_framework.mixins import ListModelMixin
from rest_framework.viewsets import GenericViewSet

# Models
from classroom.models import Quiz

# Serializers
from classroom.serializers.quiz_serializer import QuizModelSerializer


class QuizViewSet(ListModelMixin, GenericViewSet):
queryset = Quiz.objects.all()
serializer_class = QuizModelSerializer
20 changes: 20 additions & 0 deletions django_school/classroom/api_urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Django
from django.urls import include, path
from django.conf import settings

# Importing Django rest libraries.
from rest_framework.routers import DefaultRouter, SimpleRouter

# Views
from classroom.api.quiz import QuizViewSet

if settings.DEBUG:
router = DefaultRouter()
else:
router = SimpleRouter()

router.register("", QuizViewSet, basename='workers')

urlpatterns = [
path('', include(router.urls))
]
11 changes: 11 additions & 0 deletions django_school/classroom/serializers/quiz_serializer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Rest Framework
from rest_framework import serializers

# Models
from classroom.models import Quiz


class QuizModelSerializer(serializers.ModelSerializer):
class Meta:
model = Quiz
fields = ('owner', 'name', 'subject')
17 changes: 17 additions & 0 deletions django_school/django_school/api_router.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Django
from django.urls import include, path
from django.conf import settings

# Django Rest Framework
from rest_framework.routers import DefaultRouter, SimpleRouter

if settings.DEBUG:
router = DefaultRouter()
else:
router = SimpleRouter()

app_name = "api"

urlpatterns = [
path('quiz/', include('classroom.api_urls')),
]
19 changes: 11 additions & 8 deletions django_school/django_school/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))


# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/2.0/howto/deployment/checklist/

Expand All @@ -29,7 +28,6 @@

ALLOWED_HOSTS = []


# Application definition

INSTALLED_APPS = [
Expand All @@ -44,6 +42,7 @@
'crispy_forms',

'classroom',
"rest_framework",
]

MIDDLEWARE = [
Expand Down Expand Up @@ -78,7 +77,6 @@

WSGI_APPLICATION = 'django_school.wsgi.application'


# Database
# https://docs.djangoproject.com/en/2.0/ref/settings/#databases

Expand All @@ -98,7 +96,6 @@
# }
}


# Internationalization
# https://docs.djangoproject.com/en/2.0/topics/i18n/

Expand All @@ -112,7 +109,6 @@

USE_TZ = True


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/2.0/howto/static-files/

Expand All @@ -122,7 +118,6 @@
os.path.join(BASE_DIR, 'static'),
]


# Custom Django auth settings

AUTH_USER_MODEL = 'classroom.User'
Expand All @@ -135,7 +130,6 @@

LOGOUT_REDIRECT_URL = 'home'


# Messages built-in framework

MESSAGE_TAGS = {
Expand All @@ -146,7 +140,16 @@
messages.ERROR: 'alert-danger',
}


# Third party apps configuration

CRISPY_TEMPLATE_PACK = 'bootstrap4'

# django-reset-framework
# -------------------------------------------------------------------------------
# django-rest-framework - https://www.django-rest-framework.org/api-guide/settings/
REST_FRAMEWORK = {
"DEFAULT_AUTHENTICATION_CLASSES": (
"rest_framework.authentication.SessionAuthentication",
),
"DEFAULT_PERMISSION_CLASSES": (),
}
4 changes: 4 additions & 0 deletions django_school/django_school/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,8 @@
path('accounts/signup/', classroom.SignUpView.as_view(), name='signup'),
path('accounts/signup/student/', students.StudentSignUpView.as_view(), name='student_signup'),
path('accounts/signup/teacher/', teachers.TeacherSignUpView.as_view(), name='teacher_signup'),

# API urls
path("api/", include("django_school.api_router")),

]
4 changes: 4 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
asgiref==3.2.9
Django==3.0.4
django-crispy-forms==1.9.0
djangorestframework==3.11.0
pytz==2020.1
sqlparse==0.3.1