summaryrefslogtreecommitdiff
path: root/app/links/models.py
diff options
context:
space:
mode:
Diffstat (limited to 'app/links/models.py')
-rw-r--r--app/links/models.py46
1 files changed, 46 insertions, 0 deletions
diff --git a/app/links/models.py b/app/links/models.py
new file mode 100644
index 0000000..518ba33
--- /dev/null
+++ b/app/links/models.py
@@ -0,0 +1,46 @@
+from django.db import models
+from django.urls import reverse
+from django.contrib.sitemaps import Sitemap
+
+from taggit.managers import TaggableManager
+
+from taxonomy.models import TaggedItems
+from utils.util import render_images, markdown_to_html
+
+
+class Link(models.Model):
+ title = models.CharField(max_length=200)
+ link_url = models.URLField(max_length=400)
+ pub_date = models.DateTimeField('Date published')
+ slug = models.SlugField(unique_for_date='pub_date')
+ tags = TaggableManager(through=TaggedItems, blank=True, help_text='Topics Covered')
+ body_html = models.TextField(blank=True)
+ body_markdown = models.TextField()
+ PUB_STATUS = (
+ (0, 'Draft'),
+ (1, 'Published'),
+ )
+ status = models.IntegerField(choices=PUB_STATUS, default=0)
+
+ def __str__(self):
+ return self.title
+
+ def get_absolute_url(self):
+ return reverse("links:detail", kwargs={"year": self.pub_date.year, "month": self.pub_date.strftime("%m"), "slug": self.slug})
+
+ def save(self):
+ md = render_images(self.body_markdown)
+ self.body_html = markdown_to_html(md)
+ super(Link, self).save()
+
+
+class LinkedSitemap(Sitemap):
+ changefreq = "weekly"
+ priority = 0.8
+ protocol = "https"
+
+ def items(self):
+ return Link.objects.filter(status=1)
+
+ def lastmod(self, obj):
+ return obj.pub_date