{"id":13502412,"url":"https://github.com/bulkan/django-domande","last_synced_at":"2025-05-06T22:07:23.045Z","repository":{"id":6941565,"uuid":"8193153","full_name":"bulkan/django-domande","owner":"bulkan","description":"[UNMAINTAINED] A plugable Django app to represent generic questions on forms.","archived":false,"fork":false,"pushed_at":"2014-06-05T00:44:49.000Z","size":640,"stargazers_count":15,"open_issues_count":4,"forks_count":4,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-05-06T22:05:57.470Z","etag":null,"topics":["django","python","questionnaire","south"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bulkan.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2013-02-14T03:38:56.000Z","updated_at":"2018-05-27T23:05:28.000Z","dependencies_parsed_at":"2022-09-10T14:40:34.985Z","dependency_job_id":null,"html_url":"https://github.com/bulkan/django-domande","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bulkan%2Fdjango-domande","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bulkan%2Fdjango-domande/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bulkan%2Fdjango-domande/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bulkan%2Fdjango-domande/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bulkan","download_url":"https://codeload.github.com/bulkan/django-domande/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252776579,"owners_count":21802468,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["django","python","questionnaire","south"],"created_at":"2024-07-31T22:02:13.053Z","updated_at":"2025-05-06T22:07:23.027Z","avatar_url":"https://github.com/bulkan.png","language":"Python","funding_links":[],"categories":["Python"],"sub_categories":[],"readme":"![domande](https://raw.github.com/bulkan/django-domande/master/logo.png)\n\nLogo by [@aurorachiarello](http://github.com/aurorachiarello)\n\n[![Build Status](https://travis-ci.org/bulkan/django-domande.png?branch=master)](https://travis-ci.org/bulkan/django-domande)\n[![PyPi downloads](https://pypip.in/d/django-domande/badge.png)](https://crate.io/packages/django-domande/)\n\nA plugable Django app to represent a generic questions on forms.\n\n\nDependencies\n============\n\nHere are the list of dependencies;\n\n* [django-crispy-forms](http://django-crispy-forms.readthedocs.org) - This is used to render form fields with Bootstrap classes\n* [django_polymorphic](https://github.com/chrisglass/django_polymorphic/) - Provides an easy way of doing model inheritence.\n* [South](http://south.readthedocs.org/en/latest/) - For model migration. Please use it :smile:\n\n\nInstallation\n===========\n\nFor stable PyPI version\n\n    pip install django-domande\n\n\nTo get development version\n\n    pip install git+git://github.com/bulkan/django-domande.git\n\n\nIn your ```settings.py``` file change ```INSTALLED_APPS``` and add;\n\n```python\nINSTALLED_APPS = [\n   ...\n   'crispy-forms'   # need to add this for it's template tags to load\n   'polymorphic',   # provides admin templates\n   'domande'\n   ...\n]\n```\n\n__Note__ I'm assuming you have South already installed if not add ```south``` to ```INSTALLED_APPS```\n\nGeneral\n-------\n\n```domande``` uses model inheritence to simplify relationships to a list of questions and it does this with\nthe help of ```django-polymorphic```. At the moment ```domande``` supports two types of questions that are\nrendered differently by their accompanying forms.\n\nA TextQuestion were the __answer__ is a text and a ChoiceQuestion were the __answer__ is chosen \nby a set of Choices. TextQuestion and ChoiceQuestion are subclasses of Question.\n\nExample Usage\n=============\n\nModels\n-----\n\nCreate a model with a ManyToManyField to domande.models.Question. For example a Questionnaire;\n\n\n```python\nfrom django.db import models\nfrom django.contrib.contenttypes import generic\n\nfrom domande.models import Question, Answer\n\nclass Questionnaire(models.Model):\n    name = models.CharField(max_length=256)\n\n    questions = models.ManyToManyField(Question)\n```\n\n\nOnce you add a ManyToManyField to ```domande.models.Question``` and register your model with the django admin\ninterface the questions field will be handled uniquely. As ```domande.models.Questions``` is the parent model\nwhen you create a new one the admin inteface will display an additional step of choosing the child model to create an\ninstance of.\n\n\nView\n----\n\nNow you need to render the list of Questions in a view;\n\n\n```python\ndef questionnaire_view(request):\n\n    # for sake of example use .get\n    questionnaire = Questionnaire.objects.get(id=1)\n\n    forms = [q.get_form()(prefix=str(q.id),\n                content_object=request.user,\n                question=q, form_tag=False)\n                   for q in questionnaire.questions.all().get_real_instances()\n               ]\n\n    # form is a list of TextQuestionForm or ChoiceQuestionForm\n```\n\ndomande's forms accept a ```content_object``` that is used when it creates and saves an Answer.\ndomande doesn't know in advance what type of _user_ or _entry_ model you have so it uses\ndjango's builtin ```ContentType``` framework to solve this.\n\nIn the above example it uses ```request.user```.\n\n\nTemplate\n--------\n\nin the template render the forms like so;\n\n```html\n{% load crispy_forms_tags %}\n\n\u003cform method=\"post\"\u003e\n    {% for form in forms %}\n        {% crispy form %}\n    {% endfor %}\n\u003c/form\u003e\n```\n\nto process the validity of the forms and save the Answers;\n\n```python\n\ndef save_view(request, questionnaire):\n    # for sake of example use .get\n    questionnaire = Questionnaire.objects.get(id=questionnaire)\n\n    forms = [q.get_form()(request.POST or None,\n                prefix=str(q.id),\n                content_object=request.user,\n                question=q, form_tag=False)\n                    for q in questionnaire.questions.all().get_real_instances()\n            ]\n\n    forms_are_valid = []\n\n    for form in forms:\n        forms_are_valid.append(valid)\n        valid = form.is_valid()\n        if valid:\n            t = form.save()\n\n    forms_are_valid = all(forms_are_valid)\n```\n\nEach question model in domande has an Answer model that relates to it. A ChoiceQuestion will use a\nChoiceAnswer and a TextQuestion will use a ChoiceAnswer.\n\n\nDevelopment\n===========\n\n* Fork this repo, create a virtualenv and clone your fork. Then install the requirements\n\n    pip install -r requirements.txt\n\n* If you have changed the models then create a migration;\n\n    django-admin.py schemamigration --settings=domande.settings --pythonpath=$PWD\n\n* Please make sure existing tests pass and feel free to add more tests as you see fit.\n\n    django-admin.py test --settings='tests.test_settings' --pythonpath=$PWD\n\n* Submit Pull Request\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbulkan%2Fdjango-domande","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbulkan%2Fdjango-domande","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbulkan%2Fdjango-domande/lists"}