from django.db import models
from django.utils import timezone
from django.utils.translation import gettext_lazy as _

from ...core.conf import settings


class TopicFavorite(models.Model):
    user = models.ForeignKey(
        settings.AUTH_USER_MODEL,
        related_name="st_topic_favorites",
        on_delete=models.CASCADE,
    )
    topic = models.ForeignKey("spirit_topic.Topic", on_delete=models.CASCADE)

    date = models.DateTimeField(default=timezone.now)

    class Meta:
        unique_together = ("user", "topic")
        ordering = ["-date", "-pk"]
        verbose_name = _("favorite")
        verbose_name_plural = _("favorites")
