mirror of
https://github.com/pacnpal/thrillwiki_django_no_react.git
synced 2025-12-21 03:51:08 -05:00
- Cleaned up and standardized assertions in ApiTestMixin for API response validation. - Updated ASGI settings to use os.environ for setting the DJANGO_SETTINGS_MODULE. - Removed unused imports and improved formatting in settings.py. - Refactored URL patterns in urls.py for better readability and organization. - Enhanced view functions in views.py for consistency and clarity. - Added .flake8 configuration for linting and style enforcement. - Introduced type stubs for django-environ to improve type checking with Pylance.
66 lines
1.8 KiB
Python
66 lines
1.8 KiB
Python
"""
|
|
URL configuration for Parks API following Django styleguide patterns.
|
|
"""
|
|
|
|
from django.urls import path, include
|
|
from rest_framework.routers import DefaultRouter
|
|
|
|
from .views import (
|
|
ParkListApi,
|
|
ParkDetailApi,
|
|
ParkCreateApi,
|
|
ParkUpdateApi,
|
|
ParkDeleteApi,
|
|
ParkApi,
|
|
)
|
|
|
|
app_name = "parks_api"
|
|
|
|
# Option 1: Separate ViewSets for each operation (more explicit)
|
|
router_separate = DefaultRouter()
|
|
router_separate.register(r"list", ParkListApi, basename="park-list")
|
|
router_separate.register(r"detail", ParkDetailApi, basename="park-detail")
|
|
router_separate.register(r"create", ParkCreateApi, basename="park-create")
|
|
router_separate.register(r"update", ParkUpdateApi, basename="park-update")
|
|
router_separate.register(r"delete", ParkDeleteApi, basename="park-delete")
|
|
|
|
# Option 2: Unified ViewSet (more conventional DRF)
|
|
router_unified = DefaultRouter()
|
|
router_unified.register(r"parks", ParkApi, basename="park")
|
|
|
|
# Use unified approach for cleaner URLs
|
|
urlpatterns = [
|
|
path("v1/", include(router_unified.urls)),
|
|
]
|
|
|
|
# Alternative manual URL patterns for more control
|
|
urlpatterns_manual = [
|
|
# List and create
|
|
path(
|
|
"v1/parks/",
|
|
ParkApi.as_view({"get": "list", "post": "create"}),
|
|
name="park-list",
|
|
),
|
|
# Stats endpoint
|
|
path("v1/parks/stats/", ParkApi.as_view({"get": "stats"}), name="park-stats"),
|
|
# Detail operations
|
|
path(
|
|
"v1/parks/<slug:slug>/",
|
|
ParkApi.as_view(
|
|
{
|
|
"get": "retrieve",
|
|
"put": "update",
|
|
"patch": "partial_update",
|
|
"delete": "destroy",
|
|
}
|
|
),
|
|
name="park-detail",
|
|
),
|
|
# Park reviews
|
|
path(
|
|
"v1/parks/<slug:slug>/reviews/",
|
|
ParkApi.as_view({"get": "reviews"}),
|
|
name="park-reviews",
|
|
),
|
|
]
|