from django.db import models
from django.urls.base import reverse_lazy
from django.utils.safestring import mark_safe
from tinymce.models import HTMLField
from admin_ordering.models import OrderableModel
from core.utils import SingletonModel

# Create your models here.


class Post(OrderableModel):
    published = models.BooleanField('Wpis opublikowany', default=True)
    show_title = models.BooleanField('Pokaż tytuł', default=True)
    title = models.CharField('Tytuł', default='', blank=True, max_length=250)
    content = HTMLField('Treść', default='', blank=True)
    created_at = models.DateTimeField(auto_now_add=True)

    def __str__(self):
        return self.title or '(brak tytułu)'

    @property
    def link(self):
        href = reverse_lazy('home-reverse', args=[self.id])
        return mark_safe(f'<a href="{href}" target="_blank">{href}</a>')

    class Meta(OrderableModel.Meta):
        verbose_name = 'Aktualność PodlZBS'
        verbose_name_plural = 'Aktualności PodlZBS'


class GrandPrixW(SingletonModel):
    content = HTMLField('Tekst GPW', default='', blank=True)

    def __str__(self):
        return 'Grand Prix Województwa'

    class Meta:
        verbose_name = 'Grand Prix Województwa'
        verbose_name_plural = 'Grand Prix Województwa'
