diff --git a/doc/development/concepts.rst b/doc/development/concepts.rst index f9c3b78c81..5a019a4a05 100644 --- a/doc/development/concepts.rst +++ b/doc/development/concepts.rst @@ -67,6 +67,13 @@ and 'blue'. Any combination of those **values** is called a **variation**. Using the examples from above, a possible **variation** would be 'T-Shirt, S, blue'. +Questions +^^^^^^^^^ + +An item can be extended using **questions**. Questions enable items to be extended by +additional information which can be entered by the user. Examples of possible questions +include 'Name' or 'age'. + Restrictions ^^^^^^^^^^^^ diff --git a/src/tixlbase/migrations/0014_auto_20141005_1037.py b/src/tixlbase/migrations/0014_auto_20141005_1037.py new file mode 100644 index 0000000000..98694c1867 --- /dev/null +++ b/src/tixlbase/migrations/0014_auto_20141005_1037.py @@ -0,0 +1,43 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import models, migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('tixlbase', '0013_propertyvalue_position'), + ] + + operations = [ + migrations.CreateModel( + name='Question', + fields=[ + ('id', models.AutoField(primary_key=True, auto_created=True, verbose_name='ID', serialize=False)), + ('question', models.TextField(verbose_name='Question')), + ('type', models.CharField(choices=[('N', 'Number'), ('S', 'Text (one line)'), ('T', 'Multiline text'), ('B', 'Yes/No')], max_length=5, verbose_name='Question type')), + ('required', models.BooleanField(default=False, verbose_name='Required question')), + ('event', models.ForeignKey(to='tixlbase.Event', related_name='events')), + ], + options={ + 'verbose_name': 'Question', + 'verbose_name_plural': 'Questions', + }, + bases=(models.Model,), + ), + migrations.AlterModelOptions( + name='itemvariation', + options={'verbose_name': 'Item variation', 'verbose_name_plural': 'Item variations'}, + ), + migrations.AlterModelOptions( + name='propertyvalue', + options={'ordering': ('position',), 'verbose_name': 'Property value', 'verbose_name_plural': 'Property values'}, + ), + migrations.AddField( + model_name='item', + name='questions', + field=models.ManyToManyField(to='tixlbase.Question', related_name='questions', blank=True, verbose_name='Questions', help_text='The user will be asked to fill in answers for the selected questions'), + preserve_default=True, + ), + ] diff --git a/src/tixlbase/models.py b/src/tixlbase/models.py index 9358b7db66..1d0b980bc5 100644 --- a/src/tixlbase/models.py +++ b/src/tixlbase/models.py @@ -406,6 +406,47 @@ class PropertyValue(models.Model): return "%s: %s" % (self.prop.name, self.value) +class Question(models.Model): + """ + A question is an input field that can be used to extend a ticket + by custom information, e.g. "Attendee name" or "Attendee age". + """ + TYPE_NUMBER = "N" + TYPE_STRING = "S" + TYPE_TEXT = "T" + TYPE_BOOLEAN = "B" + TYPE_CHOICES = ( + (TYPE_NUMBER, _("Number")), + (TYPE_STRING, _("Text (one line)")), + (TYPE_TEXT, _("Multiline text")), + (TYPE_BOOLEAN, _("Yes/No")), + ) + + event = models.ForeignKey( + Event, + related_name="questions", + ) + question = models.TextField( + verbose_name=_("Question"), + ) + type = models.CharField( + max_length=5, + choices=TYPE_CHOICES, + verbose_name=_("Question type"), + ) + required = models.BooleanField( + default=False, + verbose_name=_("Required question"), + ) + + class Meta: + verbose_name = _("Question") + verbose_name_plural = _("Questions") + + def __str__(self): + return self.name + + class Item(models.Model): """ An item is a thing which can be sold. It belongs to an @@ -470,6 +511,16 @@ class Item(models.Model): + '\'Variations\' tab to configure the details.' ) ) + questions = models.ManyToManyField( + Question, + related_name='questions', + verbose_name=_("Questions"), + blank=True, + help_text=_( + 'The user will be asked to fill in answers for the ' + + 'selected questions' + ) + ) class Meta: verbose_name = _("Item")