Skip to main content

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

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

wagtail-rest-polls-0.0.2.tar.gz (7.7 kB view details)

Uploaded Source

Built Distribution

wagtail_rest_polls-0.0.2-py3-none-any.whl (8.9 kB view details)

Uploaded Python 3

File details

Details for the file wagtail-rest-polls-0.0.2.tar.gz.

File metadata

  • Download URL: wagtail-rest-polls-0.0.2.tar.gz
  • Upload date:
  • Size: 7.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.5.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.0 CPython/3.9.1

File hashes

Hashes for wagtail-rest-polls-0.0.2.tar.gz
Algorithm Hash digest
SHA256 4b7464a0e608dfa632a67ab9f617ee80ee2f49ac68722050f7d3dd9517b49d1a
MD5 eadbf4422e1d67cba6705385f871f5a0
BLAKE2b-256 035c7aff03c2a757aa6fe22e599b21c7b1df389b51ad3bd2480c42c1542f4e81

See more details on using hashes here.

File details

Details for the file wagtail_rest_polls-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: wagtail_rest_polls-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 8.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.5.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.0 CPython/3.9.1

File hashes

Hashes for wagtail_rest_polls-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 e180c4bde453bbb72c1b0c7c510770bfa92335dd6974967e2bceab6bcb340609
MD5 843c25dd77ec32dad4c7fee6d5713f04
BLAKE2b-256 3d34ec8584466507632e1d9c4fea3d6e7ff78d3dbd8556e808eb6fd82b38b22e

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page