Domain model - Phantawat/ku-polls GitHub Wiki

Domain Model for Iteration 1

Iteration 1: Basic Poll Structure The initial domain model for KU Polls focuses on the fundamental structure of a poll, which includes the key entities:

  • Question: Represents a poll question.
  • Choice: Represents the possible answers for a question.

In this model, each question has multiple choices, and each choice is associated with one question. image

Domain Model for Iteration 3: User and Votes

In Iteration 3, the model evolves to include user interactions and voting. The updated domain model introduces:

  • User: Represents an authenticated user who can participate in polls.
  • Vote: Links users to the choices they have selected in a poll.

Each user can vote for a choice in a question, and each vote is tied to both the user and the selected choice. This iteration allows for tracking individual user votes and enforcing voting rules such as one vote per user per poll. image

To count the number of votes for a given choice, you can use Django's ORM capabilities to filter and count the votes efficiently.

from .models import Choice, Vote

def votes(choice: Choice) -> int:
    """Return the total number of votes for a choice."""
    return Vote.objects.filter(choice=choice).count()