Skip to content

Commit

Permalink
Merge pull request #79 from codersforcauses/issue-75-documenting-APIs
Browse files Browse the repository at this point in the history
Issue 75 documenting APIs
  • Loading branch information
torry2 authored Jan 24, 2025
2 parents d1a0864 + e3d4870 commit 564afc3
Show file tree
Hide file tree
Showing 6 changed files with 517 additions and 164 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 5.1 on 2025-01-22 08:33

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("quiz", "0005_questionattempt_student"),
]

operations = [
migrations.AlterField(
model_name="questionattempt",
name="answer_student",
field=models.IntegerField(default=None),
),
]
12 changes: 12 additions & 0 deletions server/api/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
"api.users",
"api.quiz",
"api.team",
'drf_spectacular',
]

REST_FRAMEWORK = {
Expand All @@ -68,6 +69,9 @@
"rest_framework.authentication.SessionAuthentication",
"rest_framework.authentication.BasicAuthentication",
),


'DEFAULT_SCHEMA_CLASS': 'drf_spectacular.openapi.AutoSchema',
'DEFAULT_FILTER_BACKENDS': ['django_filters.rest_framework.DjangoFilterBackend']
}

Expand Down Expand Up @@ -196,3 +200,11 @@
# https://docs.djangoproject.com/en/5.0/ref/settings/#default-auto-field

DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField"

# DRF Spectacular settings
SPECTACULAR_SETTINGS = {
'TITLE': 'Your Project API',
'DESCRIPTION': 'Your project description',
'VERSION': '1.0.0',
'SERVE_INCLUDE_SCHEMA': False,
}
6 changes: 6 additions & 0 deletions server/api/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

from django.contrib import admin
from django.urls import include, path
from drf_spectacular.views import SpectacularAPIView, SpectacularRedocView, SpectacularSwaggerView

urlpatterns = [
path("admin/", admin.site.urls),
Expand All @@ -27,5 +28,10 @@
path("api/auth/", include("api.auth.urls")),
path("api/team/", include("api.team.urls")),
path("api/users/", include("api.users.urls")),
path('api/schema/', SpectacularAPIView.as_view(), name='schema'),
# Optional UI:
path('api/schema/swagger-ui/', SpectacularSwaggerView.as_view(url_name='schema'), name='swagger-ui'),
path('api/schema/redoc/', SpectacularRedocView.as_view(url_name='schema'), name='redoc'),


]
5 changes: 5 additions & 0 deletions server/api/users/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ class TeacherAdmin(admin.ModelAdmin):
class CustomUserAdmin(admin.ModelAdmin):
inlines = [StudentInline, TeacherInline]

def save_model(self, request, obj, form, change):
if form.cleaned_data["password"]:
obj.set_password(form.cleaned_data["password"])
super().save_model(request, obj, form, change)


admin.site.unregister(User)
admin.site.register(User, CustomUserAdmin)
Loading

0 comments on commit 564afc3

Please sign in to comment.