Skip to content

Commit

Permalink
Made abstract models BaseQuestion and BaseMultipleChoice
Browse files Browse the repository at this point in the history
  • Loading branch information
gabeweng committed Feb 8, 2025
1 parent bbed7cb commit b29c446
Showing 1 changed file with 41 additions and 21 deletions.
62 changes: 41 additions & 21 deletions backend/clubs/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1566,6 +1566,45 @@ def __str__(self):
return self.user.username


class BaseQuestion(CloneModel):
"""
Abstract model used to represent a question (e.g. ApplicationQuestion)
"""

FREE_RESPONSE = 1
MULTIPLE_CHOICE = 2
SHORT_ANSWER = 3
INFO_TEXT = 4
QUESTION_TYPES = (
(FREE_RESPONSE, "Free Response"),
(MULTIPLE_CHOICE, "Multiple Choice"),
(SHORT_ANSWER, "Short Answer"),
(INFO_TEXT, "Informational Text"),
)

question_type = models.IntegerField(choices=QUESTION_TYPES, default=FREE_RESPONSE)
prompt = models.TextField(blank=True)
precedence = models.IntegerField(default=0)
word_limit = models.IntegerField(default=0)

created_at = models.DateTimeField(auto_now_add=True, null=True, blank=True)
updated_at = models.DateTimeField(auto_now=True, null=True, blank=True)

class Meta:
abstract = True


class BaseMultipleChoice(models.Model):
"""
Abstract model used to represent a multiple choice selection to a question
"""

value = models.TextField(blank=True)

class Meta:
abstract = True


class ApplicationCycle(models.Model):
"""
Represents an application cycle attached to club applications
Expand Down Expand Up @@ -1691,44 +1730,25 @@ def __str__(self):
return "<ApplicationCommittee: {} in {}>".format(self.name, self.application.pk)


class ApplicationQuestion(CloneModel):
class ApplicationQuestion(BaseQuestion):
"""
Represents a question of a custom application
"""

FREE_RESPONSE = 1
MULTIPLE_CHOICE = 2
SHORT_ANSWER = 3
INFO_TEXT = 4
QUESTION_TYPES = (
(FREE_RESPONSE, "Free Response"),
(MULTIPLE_CHOICE, "Multiple Choice"),
(SHORT_ANSWER, "Short Answer"),
(INFO_TEXT, "Informational Text"),
)

question_type = models.IntegerField(choices=QUESTION_TYPES, default=FREE_RESPONSE)
prompt = models.TextField(blank=True)
precedence = models.IntegerField(default=0)
word_limit = models.IntegerField(default=0)
application = models.ForeignKey(
ClubApplication, related_name="questions", on_delete=models.CASCADE
)
committee_question = models.BooleanField(default=False)
committees = models.ManyToManyField("ApplicationCommittee", blank=True)

created_at = models.DateTimeField(auto_now_add=True, null=True, blank=True)
updated_at = models.DateTimeField(auto_now=True, null=True, blank=True)

_clone_m2o_or_o2m_fields = ["multiple_choice"]


class ApplicationMultipleChoice(models.Model):
class ApplicationMultipleChoice(BaseMultipleChoice):
"""
Represents a multiple choice selection in an application question
"""

value = models.TextField(blank=True)
question = models.ForeignKey(
ApplicationQuestion,
related_name="multiple_choice",
Expand Down

0 comments on commit b29c446

Please sign in to comment.