from django.db import models from django.utils.encoding import force_text from django.urls import reverse from utils.util import markdown_to_html class Publisher(models.Model): name = models.CharField(max_length=200) slug = models.SlugField(max_length=50) body_markdown = models.TextField(null=True, blank=True) body_html = models.TextField(null=True, blank=True) url = models.CharField(max_length=200, blank=True, null=True) payment_time = models.DecimalField(max_digits=2, decimal_places=0) order = models.DecimalField(max_digits=1, decimal_places=0) class Meta: ordering = ('order',) def __str__(self): return self.name def save(self, *args, **kwargs): if self.body_markdown: self.body_html = markdown_to_html(self.body_markdown) super(Publisher, self).save() class PubItem(models.Model): title = models.CharField(max_length=200) slug = models.CharField(max_length=50) body_markdown = models.TextField(null=True, blank=True) body_html = models.TextField(null=True, blank=True) url = models.CharField(max_length=200, blank=True, null=True) pub_date = models.DateTimeField('Date published') publisher = models.ForeignKey(Publisher, on_delete=models.CASCADE) class Meta: ordering = ('-pub_date',) def __str__(self): return self.title def get_absolute_url(self): return reverse("resume:detail", kwargs={"publisher": self.publisher.slug, "slug": self.slug}) def admin_link(self): return force_text('Visit Site' % (self.url)) admin_link.allow_tags = True admin_link.short_description = 'Live Article' def save(self, *args, **kwargs): if self.body_markdown: self.body_html = markdown_to_html(self.body_markdown) super(PubItem, self).save()