A simple polls app for wagtail in django
Project description
Wagtail Polls
This is a really simple polls app for Django and Wagtail. It has a REST interface for front-end applications (like React) or you can render it in templates.
Installation
Requirements:
- Django 3.x
- Wagtail 2.x
- Django rest framework 3.x
Start by installing the package
pip install wagtail-polls
Next migrate the models
python manage.py migrate
Add the polls app to your settings
INSTALLED_APPS = [
...
'polls'
]
Add the urls or endpoints to urls.py
from polls import endpoints as polls_endpoints
urlpatterns += path('polls/', include(poll_router))
-- and/or --
from polls import urls as polls_urls
urlpatterns += path('polls/', include(polls_urls)) # adjust the url path to fit needs
Creating a Poll
In wagtail navigate to "Snippets" and select "Polls"
You can then compelete the form and add choices as desired.
Viewing results
Results will be shown in the wagtail admin interface for each poll under the choices
API Reference
Get all Polls
GET /polls/
Response
{
"count": 1,
"next": null,
"previous": null,
"results": [
{
"id": 1,
"question": "Does this work?",
"description": "Testing 1 2 3",
"image": null,
"choices": [
{
"id": 2,
"sort_order": null,
"choice": "no",
"poll": 1
},
{
"id": 1,
"sort_order": null,
"choice": "yes",
"poll": 1
}
]
}
]
}
Get Poll
GET /polls/${id}/
Parameter | Type | Description |
---|---|---|
id |
string |
Required. Id of Poll to fetch |
Response
{
"id": 1,
"question": "Does this work?",
"description": "Testing 1 2 3",
"image": null,
"choices": [
{
"id": 2,
"sort_order": null,
"choice": "no",
"poll": 1
},
{
"id": 1,
"sort_order": null,
"choice": "yes",
"poll": 1
}
]
}
Post Vote
POST /polls/vote/
Parameter | Type | Description |
---|---|---|
poll |
int |
Required. Id of poll |
choice |
int |
Required. Id of choice |
user |
int |
optional. Id of user |
Response - returns a list of results for the poll
{
"results": [
{
"no": 2
},
{
"yes": 2
}
]
}
License
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Close
Hashes for wagtail_rest_polls-0.0.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e180c4bde453bbb72c1b0c7c510770bfa92335dd6974967e2bceab6bcb340609 |
|
MD5 | 843c25dd77ec32dad4c7fee6d5713f04 |
|
BLAKE2b-256 | 3d34ec8584466507632e1d9c4fea3d6e7ff78d3dbd8556e808eb6fd82b38b22e |