from datetime import datetime

import Models
from Models.AnalyticsModel import todays_analytics
from app import db


class DislikeModel(Models.Base):
    __tablename__ = 'dislikes'

    user_id = db.Column(db.ForeignKey('user.id'), primary_key=True)
    user = db.relationship(
        "UserModel",
        foreign_keys=user_id
    )
    dislikes_id = db.Column(db.ForeignKey('user.id'), primary_key=True)
    dislikes = db.relationship(
        "UserModel",
        foreign_keys=dislikes_id
    )
    date = db.Column(db.DateTime, nullable=False, default=datetime.utcnow())

    def __init__(self, **kwargs):
        self.date = datetime.utcnow()
        super().__init__(**kwargs)
        todays_analytics().dislikes_count += 1
