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 db.help import buttons_help_text

# Create your models here.


class Youth(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('Tekst', default='', blank=True)
    buttons = models.TextField(
        'Przyciski', default='', blank=True, help_text=buttons_help_text)

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

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

    class Meta(OrderableModel.Meta):
        verbose_name = 'Młodzież'
        verbose_name_plural = 'Młodzież'
