I sat down to write a blog post and I wrote a blog engine instead (again)

2017-07-10 blogging django

I want to write more but I've always been frustrated with the world of blog engines. Especially those available in something other than PHP and nodejs. Every time I start thinking about setting up a blog I end up spending time reviewing Ghost themes, thinking that's the right path.

Then I end up writing a simple blog engine in Django. I've probably done that more times that I've sat down to actually write posts. It usually has nothing more than a simple Post model and a couple of CBVs.

This is one of those time. This time the blog is based on the rather nice, MIT Licensed, Crisp theme by Kathy Qian. There's a credit right there at the bottom that's going to stay. It's a Ghost theme but those are always easy to translate to Django.

There's a simple Post model and manager that let's me filter to published posts. Right now I'm relying on Django admin for input (but I'm writing in Hemingway).

Here's the model in all it's glory, if you're interested:

class PostManager(models.Manager):

 def published(self):
 return self.get_queryset().filter(status=Post.STATUS_PUBLISHED)

class Post(models.Model):

        (STATUS_DRAFT, 'Draft'),
        (STATUS_PUBLISHED, 'Published'),

    author = models.ForeignKey('auth.User')
    title = models.CharField(max_length=500, blank=True, default='')
    slug = models.SlugField()

    content = models.TextField()

    created = models.DateTimeField(auto_now_add=True)
    published = models.DateTimeField(default=timezone.now)
    status = models.IntegerField(choices=STATUS_CHOICES)

    tags = TaggableManager(blank=True)

    objects = PostManager()

 class Meta:
    ordering = ['published',]

 def __str__(self):
     return self.title

 def get_absolute_url(self):
     return reverse('post', args=[self.published.year, self.id])

I'm using django-solo for the configuration management. It lets you create a singleton version of a Django model. That's rather handy.

Everything is markdown and uses mistune under the hood for conversion. I wrote a tiny template tag to let me do the conversion:

def markdown(value):
    return mark_safe(mistune.markdown(value, escape=False))

I'm going to set up and open source support for JSONFeed. I had this sorted out for Briefly but need to clean it up a little.

More soon...