Skip to content

Question models

question.models:

Question

Bases: Model

A model that refers to a built-in or customized question

Source code in question/models.py
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
class Question(models.Model):
    """A model that refers to a built-in or customized question"""

    key = models.SlugField(primary_key=True, max_length=128)
    question = models.CharField(max_length=1024)
    editable = models.BooleanField(default=True, editable=False)

    explainer=models.TextField(blank=True, default="")

    TYPES = [
        ("", "---------"),
        ("BooleanQuestion", "BooleanQuestion"),
        ("ChoiceQuestion", "ChoiceQuestion"),
        ("NumberQuestion", "NumberQuestion"),
        ("TextQuestion", "TextQuestion"),
        ("LikertQuestion", "LikertQuestion"),
        ("LikertQuestionIcon", "LikertQuestionIcon"),
        ("AutoCompleteQuestion", "AutoCompleteQuestion"),
    ]
    type = models.CharField(max_length=128, default="", choices=TYPES)

    SCALE_STEPS = [(5,5),(7,7)]
    scale_steps = models.IntegerField(choices=SCALE_STEPS, default=7)

    PROFILE_SCORING_RULES = [
        ("LIKERT", "LIKERT"),
        ("REVERSE_LIKERT", "REVERSE_LIKERT"),
        ("CATEGORIES_TO_LIKERT", "CATEGORIES_TO_LIKERT"),
    ]
    profile_scoring_rule = models.CharField(blank = True, max_length=128,  default="", choices=PROFILE_SCORING_RULES)

    # NumberQuestion
    min_value = models.FloatField(default=0)
    max_value = models.FloatField(default=120)

    # TextQuestion
    max_length = models.IntegerField(default=64)

    # ChoiceQuestion
    min_values = models.IntegerField(default=1)
    VIEWS = [
        ("BUTTON_ARRAY", "BUTTON_ARRAY"),
        ("CHECKBOXES", "CHECKBOXES"),
        ("RADIOS", "RADIOS"),
        ("DROPDOWN", "DROPDOWN"),
    ]
    view = models.CharField(max_length=128, default="", choices=VIEWS)

    is_skippable = models.BooleanField(default=False)

    def __str__(self):
        return "(" + self.key + ") " + self.question

    class Meta:
        ordering = ["key"]

QuestionGroup

Bases: Model

Convenience model for groups of questions to add at once to Block QuestionSeries from admin

Source code in question/models.py
73
74
75
76
77
78
79
80
81
82
83
84
85
class QuestionGroup(models.Model):
    """Convenience model for groups of questions to add at once to Block QuestionSeries from admin"""

    key = models.CharField(primary_key=True, max_length=128)
    questions = models.ManyToManyField(Question)
    editable = models.BooleanField(default=True, editable=False)

    class Meta:
        ordering = ["key"]
        verbose_name_plural = "Question Groups"

    def __str__(self):
        return self.key

QuestionInSeries

Bases: Model

Question with its index in QuestionSeries

Source code in question/models.py
105
106
107
108
109
110
111
112
113
114
115
class QuestionInSeries(models.Model):
    """Question with its index in QuestionSeries"""

    question_series = models.ForeignKey(QuestionSeries, on_delete=models.CASCADE)
    question = models.ForeignKey(Question, on_delete=models.CASCADE)
    index = models.PositiveIntegerField()

    class Meta:
        unique_together = ("question_series", "question")
        ordering = ["index"]
        verbose_name_plural = "Question In Series objects"

QuestionSeries

Bases: Model

Series of Questions asked in a Block

Source code in question/models.py
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
class QuestionSeries(models.Model):
    """Series of Questions asked in a Block"""

    name = models.CharField(default="", max_length=128)
    block = models.ForeignKey(Block, on_delete=models.CASCADE)
    index = models.PositiveIntegerField()  # index of QuestionSeries within Block
    questions = models.ManyToManyField(Question, through="QuestionInSeries")
    randomize = models.BooleanField(default=False)  # randomize questions within QuestionSeries

    class Meta:
        ordering = ["index"]
        verbose_name_plural = "Question Series"

    def __str__(self):
        return "QuestionSeries object ({}): {} questions".format(self.id, self.questioninseries_set.count() if self.pk else 0)