04/07 updated timezone, report via email, etc
This commit is contained in:
@@ -419,3 +419,37 @@ class CannedResponse(db.Model):
|
||||
|
||||
def __repr__(self):
|
||||
return f'<CannedResponse {self.title}>'
|
||||
|
||||
|
||||
class KBFeedback(db.Model):
|
||||
"""One thumbs-up or thumbs-down vote per user per KB article.
|
||||
|
||||
The unique constraint ensures each user can only vote once per article.
|
||||
Updating a vote replaces the existing row via the route logic (upsert).
|
||||
Votes are stored anonymously in aggregate on the KnowledgeBase table via
|
||||
two counters (helpful_count, not_helpful_count) for fast display in the
|
||||
admin list without joining this table on every page load.
|
||||
"""
|
||||
__tablename__ = 'kb_feedback'
|
||||
|
||||
id = db.Column(db.Integer, primary_key=True)
|
||||
article_id = db.Column(db.Integer, db.ForeignKey('knowledge_base.id',
|
||||
ondelete='CASCADE'), nullable=False)
|
||||
user_id = db.Column(db.Integer, db.ForeignKey('users.id',
|
||||
ondelete='CASCADE'), nullable=False)
|
||||
is_helpful = db.Column(db.Boolean, nullable=False) # True=👍 False=👎
|
||||
created_at = db.Column(db.DateTime, default=datetime.utcnow)
|
||||
updated_at = db.Column(db.DateTime, default=datetime.utcnow,
|
||||
onupdate=datetime.utcnow)
|
||||
|
||||
article = db.relationship('KnowledgeBase',
|
||||
backref=db.backref('feedback', lazy='dynamic',
|
||||
cascade='all, delete-orphan'))
|
||||
user = db.relationship('User', foreign_keys=[user_id])
|
||||
|
||||
__table_args__ = (
|
||||
db.UniqueConstraint('article_id', 'user_id', name='uq_kb_feedback'),
|
||||
)
|
||||
|
||||
def __repr__(self):
|
||||
return f'<KBFeedback article={self.article_id} user={self.user_id} helpful={self.is_helpful}>'
|
||||
|
||||
Reference in New Issue
Block a user