Quiz Creator App With Django

Atufa Shireen
3 min readJun 8, 2021

--

An application that would let you create, edit and attempt quizzes (intended for tech quizzes), along with keeping a profile. .Here’s a breakdown of the project:

I used designs from the previous blog project(Bad at UI)

Apps

The project is divided into 2 applications:

  1. users: For handling user’s profile.
  2. quiz: For handling quizzes.

Models

  1. Profile: A model for storing a user’s data (built-in User Model), bio, and profile pictures. I used Cloudinary for saving user’s uploads on the cloud.
  2. Quizzer: Stores quiz’s title, author (Foreign Key to User), private(For keeping quizzes unpublished), Reattempt( Boolean value for allowing multiple attempts), bg_pic (background picture for quiz modal, stored in the cloud with Cloudinary field), tags (Used taggit for creating a taggable object). Questions of the quiz, number of attempters, tags are retrieved using class methods.
  3. Questions: Stores question text, options(limited to 4), points(for particular question), answer( created a custom RangeField for limiting values to 4) and obviously a foreign key to Quizzer model, quizz.
  4. QuizScore: Stores user’s(Foreign Key to User) score(Integer Field) of the quiz(Foreign Key to Quizzer).
  5. AnonymousUsersData: stores user’s name, the score for quizzes attempted by shareable quizzes.

Forms

  1. QuizForm: A model form for taking Quizzer fields.[tags limited to 3 or more]
  2. QuestionsFormset: A formset for taking multiple Questions model inputs.
  3. UserRegsitrationForm: Form for registering users, used built-in UserCreationForm.
  4. UserUpdateForm: Form for updating user’s data (name and address).
  5. ProfileUpdateForm: Form for updating user’s profile (bio and pic).

Urls

  1. / : Home Page for all quizzes.
  2. /register/ : Registration Page.
  3. /login/ : Login Page.
  4. /profile/ : Logged In user’s profile.
  5. /profile/<str:view_user>/ : For viewing other‘s profile.
  6. /quiz/add/ : Adding quizzes.
  7. /quiz/edit/<str:quiz_tit>/ : For editing quiz.
  8. /quiz/shared/<slug:username>/<slug:quiz_name>/<str:id>/ : Url pattern for shared quizzes.
  9. /quiz/<str:slug>/ : Page for attempting quiz.
  10. /api-auth/: Api Views for all the pages.

Views

  1. ShareQuizzView: The view let’s anonymous users to attempt shared quizzes and adds the user’s data to AnonymousUsersData models.
  2. add_quiz_form: Adds quizzes via QuizForm and QuestionsFormset, at least one is required, needs the user to be logged in.
  3. edit_quiz_form: formsets are used for editing the quizzes, allows authors to edit quizzes by their title.
  4. QuizzView: allows attempting public quizzes by the users, redirects if reattempts are not allowed or quiz doesnot exists, and updates or adds the score of the quiz to the user’s profile data.
  5. Quizzes: Lists the quizzes which are public by other users, and are not yet attempted by the user. Search feature is available
  6. register: Register users with built-in registration form. Signals are used to create profiles of the registered users.
  7. profile: Allows users to update their name, bio, pic and created quizzes, including private and public quizzes with a share option. Lists all the user’s public and attempted quizzes with their score.

Settings

  1. Secret Keys are stored using decouple, which lets you read values from environment variable. Since the application is hosted on heroku, secret key’s are stored in heroku’s environment variables.

2. taggit was used to store tags, widget_tweaks for adding attributes to jinja tags, cloudinary for storing user’s upload.

3. whitenoise used for storing static files, dj_database_url for updating database to heroku’s default database.

4. Factory Boy used for generating fake quizzes and users.

Data generated with factoryboy (just random words)

python manage.py setup_test_data command (present at QuizCreator/quiz/management/commands/) generates fake data.

Github Link: https://github.com/AtufaShireen/QuizCreator.

Project Link: https://quizzier.herokuapp.com/.

--

--