In this sixth Django web development with Python tutorial, we're going to cover working with models in Django. Our plan is to add the final element of our website: a blog. So far, we've worked with views and a controller, but have not really done anything with models.
First off, what are models? Models contain "meta data" regarding your application's data. Generally, these models are used to describe just the elements in your database, but they can be built up to be much more than just that.
Second, we know we want to make a blog. Is this blog a part of our "personal" website, or would it make more sense to be its own app? It could be a part of our personal app, but it really ought to be its own entirely. Plus, chances are, we're going to want to incorporate a blog on other apps, so let's make a new app: python manage.py startapp blog.
We just added a new app. What is the first thing we should do? Right, install it!
Homepage
Hacker Noon
LatestEditors' ChoiceTerms FAQSign up for 2.0Join Community
How Wedding Together added a blog to their Django app in 5 minutes
Go to the profile of Roger Jin
Roger Jin
Jul 13, 2017
Our Problem
We’re python developers and we want to add a blog to Wedding Together. Wedding Together is a mobile app that allows wedding guests to share photos they take at weddings. Adding a blog to a website is a problem as old as the internet. If we find ourselves reinventing the wheel, we’re probably doing it wrong. I could discuss building our own blogging system from scratch, but there are already plenty of articles on how to do that.
Our Requirements
We don’t want to worry about SEO. It should come built-in.
We want to put whatever code we pull from GitHub to live at weddingtogether.co/blog without any NGINX/Apache witchcraft.
We don’t want to be editing HTML files or writing code every time a content change is made.
One requirement makes a clear separation between all the paths we can take. We want to protect and improve our development processes.
If we don’t want:
a separate set of SASS stylesheets just for this blog.
to spend time managing security updates.
to mess with our current configuration.
to role our own solution.
Our option is to pick a managed solution. We’ll go over those second. If we’re ok with some of those things, then we have two self-managed options.
Our Options
Self Managed
The two most popular python web frameworks are Django and Flask. Wedding Together’s backend is built with Django, so we’ll start there. A few Google searches later we find Mezzanine to be the most active Django blog project. If the best option involves the downside of creating an additional application to take care of, we might as well look up options in Flask. The two most used options are flask-blog and Flask-Blogging. flask-blog hasn’t been updated in 3 years. Flask-Blogging is our “Mezzanine level” blog option but in Flask. Both Mezzanine and Flask-Blogging have the following pros and cons:
Pros:
Has all the bells and whistles out of the box. We don’t want to deal with things like SEO and meta what-not.
Hackable if we want to make modifications
Simple non-developer interface for making blog posts
“Free” (explained below)
Cons
Requires us to manage and maintain another application
Depending on how your infrastructure is setup, adding another application could be as simple as pip installing on a server or as difficult as adding another machine to your already growing architecture.
Most web/software companies have one resource that they’ll never get enough of, developer time. Mezzanine and Flask-Blogging are “free” if you don’t consider developer time. If you account for developer time in implementing these options, they are among the most expensive options you could pick.
Managed For Us
Let’s look at a managed option that is almost free in a sense of developer time. ButterCMS is a managed blog option with the most developer friendly API possible. I’ve tried out half a dozen blog API options and ButterCMS is truly the easiest and most simple.
We log into the interface on their site to write a blog post.
https://qaisarabbas.com