Skip to content

Polls Models Documentation

Database Tables

Table Name Description Fields
tbl_question Stores questions related to products. id, product, user, question, created_at, updated_at
tbl_answer Stores answers related to questions. id, question, user, answer, created_at, updated_at, vote_count
tbl_vote Stores votes for answers. id, user, answer, value, created_at, updated_at

Models Details

Question

  • Description: Represents a question related to a product.
  • Fields:
  • product: ForeignKey to Product, related name product_question.
  • user: ForeignKey to User, related name user_question.
  • question: Text field storing the question text.
  • created_at: Timestamp when the question was created.
  • updated_at: Timestamp when the question was last updated.

  • Properties:

  • vote_count: Computes the sum of votes for all answers related to the question.

Answer

  • Description: Represents an answer related to a specific question.
  • Fields:
  • question: ForeignKey to Question, related name question_answer.
  • user: ForeignKey to User, related name user_answer.
  • answer: Text field storing the answer text.
  • created_at: Timestamp when the answer was created.
  • updated_at: Timestamp when the answer was last updated.
  • vote_count: Integer field storing the total count of votes.

Vote

  • Description: Represents a vote for an answer.
  • Fields:
  • user: ForeignKey to User, related name user_vote.
  • answer: ForeignKey to Answer, related name answer_vote.
  • value: Integer field indicating vote value (+1 for upvote, -1 for downvote).
  • created_at: Timestamp when the vote was created.
  • updated_at: Timestamp when the vote was last updated.

  • Constraints:

  • Unique constraint on user and answer, ensuring each user can vote on an answer only once.