2.7 KiB
2.7 KiB
dg-surv
A Django survey API service with an admin panel for building surveys and public JSON endpoints for anonymous responses.
What is included
- Welcome page at
/ - Browser documentation at
/docs/ - Modern Django admin styling for survey management
- Public survey schema API
- Anonymous response submission API
- Built-in validation for text, choice, rating, and yes/no answers
- CORS headers for
/api/ - Django tests for core API behavior
Setup
python -m venv .venv
.venv\Scripts\activate
pip install -r requirements.txt
python manage.py migrate
python manage.py createsuperuser
python manage.py runserver
Open:
- Welcome page:
http://127.0.0.1:8000/ - Documentation:
http://127.0.0.1:8000/docs/ - Admin panel:
http://127.0.0.1:8000/admin/ - API index:
http://127.0.0.1:8000/api/surveys/
Creating a survey
- Create a survey in the admin panel.
- Add questions inline on the survey page.
- For single-choice or multiple-choice questions, open the question record and add choices.
- Set the survey status to
Published.
Supported question types:
short_textlong_textsingle_choicemultiple_choiceratingyes_no
Public API
List published surveys:
GET /api/surveys/
Read a survey schema:
GET /api/surveys/customer-feedback/
Submit a response without authentication:
POST /api/surveys/customer-feedback/responses/
Content-Type: application/json
{
"respondent_email": "person@example.com",
"metadata": {
"source": "website"
},
"answers": [
{
"question": "name",
"value": "Alex"
},
{
"question": "experience",
"choice": "good"
}
]
}
answers can also be an object keyed by question slug:
{
"answers": {
"name": "Alex",
"score": 5,
"subscribe": true
}
}
Choice answers accept either the choice value or choice id.
Documentation
Detailed API documentation is available in two places:
- Browser page:
http://127.0.0.1:8000/docs/ - Markdown guide: docs/API.md
Configuration
Environment variables:
DJANGO_SECRET_KEY: required for production deployments.DJANGO_DEBUG: set to0in production.DJANGO_ALLOWED_HOSTS: comma-separated host list. Defaults to*.SURVEY_API_CORS_ORIGINS: comma-separated origin list for/api/. Defaults to*.
Run tests:
python manage.py test
Project layout
survey_service/ Django project settings and root URLs
surveys/ Survey models, admin, API views, tests, middleware
templates/ Welcome page, docs page, admin override
static/surveys/ Admin and public page styles/assets
docs/API.md Markdown API guide