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 toProduct, related nameproduct_question.user: ForeignKey toUser, related nameuser_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 toQuestion, related namequestion_answer.user: ForeignKey toUser, related nameuser_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 toUser, related nameuser_vote.answer: ForeignKey toAnswer, related nameanswer_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
userandanswer, ensuring each user can vote on an answer only once.