Django Quiz - Introduction

Introduction

Taking 5-10 minutes to read this post before moving on to the code will be helpful.

Creating a quiz takes a little more than what is obvious at first sight.
Let’s assume a super simple sleep quality quiz.

There are five key concepts to keep in mind:

  • Quiz
  • Questions
  • Dimensions
  • Answers
  • Profiles

 

Quiz

This is the simple part. Defining a quiz is a matter of choosing a name for it.
It works as a reference for other elements, such as questions and answers.

 

Questions

Each question inevitably belongs to a specific quiz.

 

Dimensions

We can think of dimensions as intermediate results of the quiz.
They are not visible to the user.

For a quiz about sleep, possible dimensions could be:

  • Sleep Quality
  • Sleep Stress
  • Sleep Regularity

 

Basic rules for defining good dimensions

  • They measure something continuous
  • They represent something real and observable
  • They are independent from each other
  • They are influenced by multiple answers
  • They carry no interpretation or judgment
  • They are few and stable (3 to 5)
  • They are reusable
  • They exist to structure results

 

 

Answers

Upon defining our answers we go deeper into dimensions.
 

 

To every answer, we associate one or more dimension values (weights).

The key word here is coherence.

To create a reliable quiz, the weights assigned to each dimension must make sense across different questions and answers.

 

 

Example: assigning dimension weights

 

1. How often do you wake up during the night?

  • Never or rarely | quality +2 | stress -1 
  • Once per night | quality +1 
  • 2–3 times per night  | stress +1 
  • Many times per night | quality -2 | stress +2 
     

2. What time do you usually go to bed?

  • Before 11pm | quality +1regularity +2
  • Between 11pm and midnight | regularity +1
  • After midnight | quality -1 | stress +1 | regularity -1
  • Very irregular schedule | quality -1 | stress +1 | regularity -2
     

3. How do you feel when you wake up?

  • Rested and full of energy | quality +2 | stress -1 
  • So-so
  • Tired | quality -1 | stress +1 
  • Exhausted | quality -2 | stress +2 
     

4. Do you think about problems when you go to bed?

  • Almost never | quality +1 | stress -2
  • Sometimes | stress +1 
  • Often | quality -1 | stress +2 
  • Always | quality -2 | stress +3

 


Assume that upon completing the quiz we obtain the following result:

  • Quality: -7
  • Stress: 8
  • Regularity: -2


The next step is to create rules that associate these dimensions with a profile.

 

 

Profiles

 

There is no strict rule, but the following ratios are a good guideline:

3 dimensions 5 a 7 profiles
4 dimensions
6 a 10 profiles
5 dimensions
8 a 12 profiles

 

 

Profiles represent the final results of the quiz. For example:

  • Balanced Sleeper
  • Light Sleeper
  • Stressed Sleeper
  • Irregular Sleeper
  • Poor Sleep Quality

 

 

 

 

Rules

 

Once again, coherence.

 

 

To create a reliable quiz, the rules defined for each profile must make sense when compared across different profiles.

Example rules:

 

Balanced Sleeper

  • quality ≥ 4
  • stress ≤ 2
  • regularity ≥ 0

Light Sleeper

  • quality ≥ 3
  • stress between 2 and 4
  • regularity ≥ 0

Stressed Sleeper

  • stress ≥ 4
  • quality ≤ 3

Irregular Sleeper

  • regularity ≤ -1
  • quality ≤ 3

Poor Sleep Quality

  • quality ≤ 2
  • stress ≥ 3
  • regularity ≤ 0

 

 

 

A new challenge appears (intentionally triggered here): the result activates three valid profiles.

  • Stressed Sleeper
  • Irregular Sleeper
  • Poor Sleep Quality

This leads us to the final criterion: each profile must have a priority.

 

 

Priority


Priorities are as simple as assigning an integer value to a profile. The real challenge lies in assigning the correct priority.
 

  • Severity: profiles that indicate clear or impactful problems should override mild interpretations.
  • Specificity: specific explanations should take precedence over generic or fallback profiles.
  • Dominant signal: when one dimension strongly stands out, profiles driven by that dimension should win.
  • Communication intent: priority should reflect the most useful and responsible message to present to the user.

 

Example:

          Priority                    Profile           
1 Poor Sleep Quality
2 Stressed Sleeper
3 Irregular Sleeper
4 Light Sleeper
5 Balanced Sleeper


And having these three profiles in target:

  • Stressed Sleeper
  • Irregular Sleeper
  • Poor Sleep Quality

We can conclude that the profile that best fits this result is Poor Sleep Quality, since it has the highest priority.

 

In the next post, we will get our hands into the code and define the models for this scenario.

 

 

Fallback Profiles

 

Even with well-defined rules and priorities, there may be cases where no profile matches the final dimension scores.

To handle these situations, we introduce fallback profiles.

  • A fallback profile is a regular profile, with the lowest priority.
  • Its rules are either very broad or ignored.
  • It only applies when no other profile is activated.


This ensures that every quiz result produces a meaningful outcome, without introducing a new type of profile.
 

Undefined Sleep Pattern

  • quality ≥ -999
  • stress ≤ 999
  • regularity ≥ -999
     
          Priority                         Profile                
6   Undefined Sleep Pattern