Spicing up Django: An Introduction to Mezzanine CMS by Ed Rivas

This video features Ed Rivas at DjangoCon US 2016 in Philadelphia, Pennsylvania, USA.

Spicing up Django: An Introduction to Mezzanine CMS by Ed Rivas
0:22:18
Published August 12, 2016
1,765 views

Spicing up Django: An Introduction to Mezzanine CMS by Ed Rivas

Mezzanine CMS is a popular content-management solution for Django. With a rich set of built-in features and following Django’s batteries-included approach, it can supercharge your new or existing apps for content-oriented sites.

In this talk we will explore the features that Mezzanine provides by default, and how they take care of many common content-management tasks (page creation and editing, maintaining a blog, WYSIWYG editors, SEO, and more).

We will also take an existing Django app and convert it into a fully integrated Mezzanine application. You’ll be surprised at how much of the work has been done for you, and how your existing Django skills will let you hit the ground running when working with Mezzanine.

Outline:

Mezzanine tour
Basic integration of custom models
Advanced integration of custom models
Working with templates
Review
Questions (if time permits)

This talk was presented at: https://2016.djangocon.us/schedule/presentation/17/

LINKS:
Follow DjangCon US 👇
https://twitter.com/djangocon

Follow DEFNA 👇
https://twitter.com/defnado
https://www.defna.org/

Summary

Ed Rivas presents Mezzanine as a Django-based content management platform that adds batteries-included features such as blogs, hierarchical pages, scheduled publishing, permissions, search, and multi-site support. He demonstrates converting Django’s tutorial polls app into a Mezzanine-integrated application by inheriting from `Displayable` for titles, slugs, drafts, publication dates, metadata, and expiry, using the published manager in queries, and inheriting from `Orderable` for drag-and-drop inline choices. He also covers Mezzanine’s admin and template integration, Bootstrap defaults, file management, custom page types, deployment scripts, page processors, e-commerce, editable settings, and the documentation and blog app as further examples.

Key takeaways

  • Mezzanine is designed as “just Django,” so existing Django models, views, templates, admin classes, and project conventions remain usable.
  • The `Displayable` model adds titles, slugs, draft and published status, scheduled publication, expiry, metadata, and related admin functionality.
  • Using Mezzanine’s published manager ensures public views return only content that is currently published.
  • The `Orderable` model and dynamic inline admin classes provide drag-and-drop ordering and flexible creation of related objects.
  • Mezzanine includes additional CMS features such as hierarchical pages, a file manager, custom page types, deployment scripts, e-commerce, WYSIWYG editing, and user-editable settings.

Summarised automatically from the transcript.

Chapters

  1. 0:00 Introduction to Mezzanine Ed Rivas introduces Mezzanine, its Django foundation, core features, and content-management philosophy.
  2. 1:02 Mezzanine Architecture and Features An overview of Mezzanine’s batteries-included approach, permissions, extensibility, blog, navigation, and publishing capabilities.
  3. 2:42 Installation and Project Setup The talk demonstrates installing Mezzanine, creating a project and database, and exploring the default site.
  4. 4:21 Integrating a Django Polls App A standard Django polls application is added to Mezzanine with its models, admin, URLs, and views.
  5. 6:38 Publishing Requirements for Polls The example application is expanded with drafts, scheduled publishing, expiration dates, slugs, ordering, and SEO-friendly URLs.
  6. 8:09 Displayable Content Models The Displayable model provides titles, slugs, metadata, publication status, and scheduling for public-facing content.
  7. 10:27 Mezzanine Admin Integration The Displayable admin class adds publishing controls, metadata panels, filtering, search, and date-based navigation.
  8. 12:02 Published Queries and Content Ordering The published manager restricts public views to live content, while Orderable enables sortable, dynamically created inlines.
  9. 15:08 Templates and Bootstrap Themes The polls application is integrated with Mezzanine templates and the default Bootstrap-based theme.
  10. 16:39 Conversion Checklist A concise review covers Displayable models, Orderable inlines, published queries, and Mezzanine template blocks.
  11. 17:29 Additional Mezzanine Features and Resources The speaker surveys custom page types, file management, deployment scripts, page processors, e-commerce, editors, settings, and further reading.
  12. 21:00 Questions The speaker answers a question about Mezzanine’s compatibility with non-relational databases through Django.

Transcript

3,640 words · auto-generated Show

Automatically transcribed, so expect mistakes in names and technical terms.

0:00

Speaker 1: Come on, no.

0:14

Speaker 2: Okay, um yeah, I'm Ed. Um I'm a contributor to Messening CMS. In this talk, I want to take us in a journey to explore the features that Mesani provides by default and how can uh How they can help you with your Django knowledge to really make the most out of it and create great content-oriented sites. We're also going to explore creating Taking an existing uh Django app and converting it to uh fully integrated mesanine app. Right, so I wanna start by talking a little bit about mesanine ZMS. Who here uh knows anything? about mesanine? Alright, so this intro is gonna be needed. Well this here's a little bit of trivia for you.

1:02

Speaker 2: It was created by Stephen McDonald, a guy a guy from Australia. It's been under development for seven years now with uh uh comet activity every week. Um it has more than 275 contributors. You can also find a very helpful community. We have a very active mailing list and where you can get development and and support in general. It's well documented, I believe. And you also have a variety of third-party packages, many of them available through PIP2. So now a little bit more about the architectural or philosophical side of mezzanine. Mezzanine is a very powerful, consistent, and flexible content management platform. It provides a very simple yet highly extensible architecture that encourages diving in and hacking on the code.

1:53

Speaker 2: You'll get the same batteries included approach as Django but applied to content management. You get a blog for free, uh hierarchical page navigation, scheduled publishing of your pages, uh multi-tenancy support for multiple sites. And there's a huge list of features that are there for you. Messanin also inherits a bunch of Django's fine-grained permission controls, security best practices, of course. And you'll be able to leverage much of the goodies and things that you already know about Django in your messenger application. But maybe the most important thing about uh mezzanine is it is just Django. It's right there in the docs if you go uh check them. There's a quote that says Mesending is just Django, so everything you know about writing models, about writing uh views, about writing um

2:42

Speaker 2: uh templates will be uh good for you and you'll be able to hit the ground running if you know at least a little bit of Django already. Alright, so let's get started now and convert a a small application. Well, let's get started installing messenger and then convert an application to work with it. So as you can see as any other Python package, you can install it via pip. It will download all the dependencies including Django. Then you can run this messaging project command, which don't get scared, it's just a wrapper around Django's Django project command, and it will give you the started project layout or project template. With some of the settings and URL configuration already filled in for you, but other than that it's just a regular Django

3:32

Speaker 2: project. Then after that you run create database, create DB Which the same thing is just a wrapper around uh migrate from Django. You only uh needed to get the to create a default user, a super user, and if you want you can also install some demo content for you to get started quickly. And after that run server, which is just a standard Django command. Exactly. So now you open your browser in y in localhost and this is what you get out of the box. Uh you have a complete uh nested page tree, you've got inside search, you've got a basic bootstrap template. You've got a blog and many many other things just for free just for installing mesinine uh via pip. So let's write our own application or convert one uh

4:21

Speaker 2: a standard Django application to better integrated with Mesanin. Yeah, it starts in like 14 minutes since yeah, it's hard. So I'm gonna use the poles application because I think it's well known. If you have ever completed the Django tutorial, it's just a very simple application. I like it because it will let us play with two models, the Pulf model. If you remember it just has a question prompt And then it has the choices which are an inline model that you'll be able to give options to answer the question you're calling about. This is editable via the admin site. You just register the admin class. It has a list and a detailed view too. And it will handle form input like voting. This is what the poll application does by default

5:07

Speaker 2: when you complete the tutorial. So how do you install an application in Messnin? Well it's just like a any Django project. You odd you add your app to install the apps and settings. You wire up your URL configuration and finally you run migrations, if any, and you're up and running. Of course if Your app is more complex and you need to define custom middleware, you need to define context processors or anything like that, you can do it. It's just like installing anything on Django So right after doing that and and adding the the pulse application as it came from the tutorial directly into the messaging project. This is what you get. Mesanin uses Grapholey as the admin

5:53

Speaker 2: interface, but other than that you don't need any changes in your admin class or your model definition or anything to get this working. You get the regular Model admin and also the inlines just as you define them in the regular application. And the public facing views also work as you would expect it. This is the the view that comes with the poll app Again, you just wire the URL configuration and you'll get this working out of the box without any changes. So let's spice it up a little bit. Let's say that some new requirements come in and you want to change the behavior of the application. So we can do that, but let's define those requirements. Let's say you want a publishing workflow, and what do I mean with a publishing workflow?

6:38

Speaker 2: that uh we want some application some polls to be able to be set on drafts. For example, if our admin users they're creating a new poll but they don't want to publish it right away, they can save it in the admin. um save it as draft and it will not be available in the public side. So they can come back and work on it later. We also want them to be able to schedule publishing Well then to be able to to say uh okay this poll is gonna be live uh gonna go live in uh next week, Monday midnight And we also can uh set expiration dates and we want to say okay this poll is gonna expire uh next Friday at the end of the day We also want the most recent polls to appear first, so we want to have some way to control

7:23

Speaker 2: which app which poll was uh published recently, right? Which is a common requirement. We also want to use logs instead of primary keys in the URL, so our URLs for SEO and readability purposes. Maybe we don't want to have you know my site. com slash poll slash 43. When we can have uh poll slash my awesome poll, you know, more shareable and more readable. And we also want the choices to be sortable in our admin users, let's say They have the choices and they just don't want to sort them as they add them. Maybe they want to change the sorting after that. So how are we going to do that with messenge? Well, well this is the original model, the original poles model. If you can you very easily

8:09

Speaker 2: just a single field, the question, which is just a text from for users to insert the question Now the displayable model, this is one of the base models that ships with methane in and this is the one that you're going to be inheriting a lot. It's the base for all public facing content pieces in Messening. This is what's going to add the draft publish its status to our model instances. This is the same as going to allow you for scheduled publishing. It can auto-generate slugs from your child and just create them automatically, though you can override these slugs if you want to craft them yourself. And it comes with some helper admin classes and manager for that. You're gonna get some fields by default. You're gonna get a title field, you're gonna get a meta

8:57

Speaker 2: title field if you want to change how the the piece of content appears in the browser title bar You're gonna get this log field which is gonna be which can be auto-generated or you can customize it. You also get a description in case you want to automatically populate the um the browser meta description with the description from your content or the content from your page. You also get a publish date, which is going to be a standard Django daytime object which you can manipulate later. You also get the status where you're going to be able to check whether a piece of content is published or is set as draft and a bunch more which are not important right now. So we're gonna inherit from this model we just imported from mezzanine

9:42

Speaker 2: and yeah, we just subclass it And that's it. We actually can get rid of the question prompt because the model is gonna define its own title field. And that's what we're gonna use for the question. And yeah, just inherit from it. Of course, in case you need to add more fields, you can do it normally. Create your own Django fields and customize. If we want to say, oh, each fold is going to have a picture, for example. Okay, a file field right there. And this is the original admin. You can see we have to define our fields. We want to define the inlines to display the choices. We want to define who's going to be displayed in the least view and we want to define who is going to be searchable from the admin.

10:27

Speaker 2: So this is the original one that came from the Pulse application And this is how it looked. And we're gonna use now the displayable admin class on that. On that. And this is the same. We're just gonna um inherit from Mesanin And just the only change we need to do is tell it which inlines we want to use, right? The choices, the little choices behind it, uh after it. We just need to specify that because we'll see how it this will change the admin interface So this is a new admin you get, and you can see you get well the title, that's our old question prompt. We use that now. This log will be generated from that and automatically you can use it in your views to retrieve the object. You also get uh the draft and publish uh toggle for your users to peek if they want the

11:17

Speaker 2: the um The content to be drafted published. You can set the publish from and expires on dates to define when should something be available in the public site or not And in the metadata panel, which this one is a collapsible panel, it will allow you to tweak the generated slog, add meta keywords, add a description, and choose if you want to include this page in your site's sitemap. And in the least view, we're gonna get a full search on the title of the polls. We're gonna get a date hierarchy on the published date. We're gonna be able to filter um by status and you're you're going to be able to switch out um the uh

12:02

Speaker 2: the published status of the pie the the polls right from the least view. So all of these we just got from inheriting from Mesanine's models and mesonine admin classes So now how about the view? If we if we know that our polls are going to be some are going to be drafted and some are going to be published, we of course only want uh users to be able to see the published ones, we simply have to use the published manager. Basically what you have to do and this is a very simple class-based view, the one that again is shipped with the Pulse application, we the only thing you want to do is when you're getting your query set, either on a class-based view or a function-based one, instead of doing objects.

12:51

Speaker 2: all, you do objects. publish. And with that, with the manager that comes to methoding, you already are going to return only the published ones. You have to worry that your public -facing users, your public site users are going to see content that's not meant for them to see. And after that you can do the order by the published date to get the most recent polls first. Yeah, so this is what the view ends up looking like. You get the polls And then you have them sorted by how recently were they published. The next thing is what we were talking about being able to sort uh the The little inlines, the little choices.

13:37

Speaker 2: Like we want we don't want to have the choices appear as they were added. Maybe the use the admin users want to have You know, I want this one on top, let's move this one to the bottom. So we're going to use the orderable model, which also uh ships with mezzanine. Uh it's ideal for solarable inlines, it comes in both stack and tabular varieties You can drag and drop sort with it. And it will also support dynamic creation for more inline forms. So you don't have to define the extra. how many extra inlines you want to show to the user, they can just keep creating them and populate them. Of course you can limit that with the standard Django admin classes. So it's the same here. We're gonna we're gonna edit our choice model. We're going to inherit from orderable

14:23

Speaker 2: and just set a foreign key to our old poll model. Set the choice text. And set the integer field for to store how many votes has each choice got. And in the admin class, we only inherit from tabular dynamic inline admin There's also the stack it variety and this is what you get. You get your choices and you get those little handles which you can sort. Users can use their mouse to sort them. You know, they can use any arbitrary ordering they want. And they also get the little add another button Which will let them create as many inlines as they want. They don't have to do three at a time or anything like that. And lastly, well

15:08

Speaker 2: some templates. I'm just gonna go uh quickly over this because we don't have much time Not very pretty, but you know you can write any CSS you want, it gets you all that flexibility But if we go ahead and edit it to extend some of the of the basic templates that come with messaging already, if you for example extend the base HTML template, use the title block and Put all your main content in this main block. This is what you get. You get it integrated into the bootstrap theme Now here I know you might have different opinions on bootstrap and everything.

15:54

Speaker 2: The point here is not to make you use bootstrap. I don't want you to think that oh mezzanine is bootstrap then I cannot do anything out of it. It's just there as a default to get you up and running quickly. You want to show a prototype quickly? You want to use a free bootstrap theme? This is for you then you only have to uh extend methanine templates and use the right blocks and you can get something like this very quickly So let's review what we did, the step that we followed to convert a regular Django application into a regular, into a fully integrated Mesonite app. So in the models, the your main models you're gonna be able to you're gonna want to evaluate if you want to inherit from displayable to get you the

16:39

Speaker 2: all the public facing goodies that we reviewed before, the auto-generated slog. the uh published status, the schedule publishing. For inlines, you're gonna probably gonna want to inherit from orderable to get that drag and drop ordering on your models. When you're making queries in your database, in your views or whatever, you want to use objects. publish instead of objects. all to make sure that scheduled publishing is working as expected. And then for templates you want to use extend mesanine blocks. You want to use the mesanine-included templates if you want to use Bootstrap on your site and just get that site up and running quickly. Now there's a whole bunch of things that I haven't even thought uh talked about here.

17:29

Speaker 2: Uh messadine supports custom page types so your users can You can create custom pages that your users can use when creating the page three in Messenine. You also have a complete file manager in your server. Means users can upload and manage their files. Instead of just having that little form file input in your forms in your admin, you can have one that lets them browse inside the media that already exists in the site And it's much more easier to work like that. Uh mezzanine also ships with a series of fabric scripts that you can use to automate deployment. So if you get a five dollar VPS from From uh any web hosting provider online. You can get up and running very easily, even if you haven't uh

18:17

Speaker 2: done any Django deployments before It also has page processors that will let you it's like writing views but for your custom pages and will let you inject content context into the template whatever you need it It also has an e-commerce module where you're gonna be able to uh integrate a shopping cart and uh shopping categories and prices and variations It also has a WISIWIC editor, which is swappable. In case you don't like the default, you can define very easily your own custom class and include your uh media to be used instead of the default. It also has user editable settings which will allow your users For maybe stuff very simple like uh I don't know uh what's your your site's Facebook or Twitter URL and you just want to type that in.

19:05

Speaker 2: You don't want that inversion control We want that for them to edit it in the admin and it's easier. And you can use it whatever you want in the backend or in your templates. So there's a little bit more you can read. I mean what can you do after this talk? SME has a page in their documentation that's called the content architecture. And I think it's one of the most important pages. It goes into detail of what I've explained here, what is the displayable model. uh what are you supposed to do with it. It also has another strategy uh for creating custom page types, which is um out of the scope of this talk but you you should read that.

19:50

Speaker 2: There's a couple of community blogs that you're gonna be able to to read too that's very good on some uh specific uh battle tested patterns to develop uh mesanine applications And there's also the messenger blog application. As I told you, out of the box, you're gonna get a blog for your site This blog application uh is a I think is a great case study of a non-trivial app developed for messenger because it it has a good deal of use, it has much more complex models, it has its own template tags. So it's a good way to see how you're gonna create a more robust, complex application that is integrated with Messening. And there's no links there but I'm gonna share the the slides later and they will have links.

20:36

Speaker 2: So thank you. I left some uh the the slide URLs there and my and there's a repo for this um All everything we went through here, which you can use uh to better understand how to convert your Django app to a messenger app.

21:00

Speaker 3: Hey. Uh It's it's nice uh to understand how mercenine works. I just have a curious question that since Mercenine is talking more about uh the content right so how what is the sub level of support that it can provide for a NoSQL uh type uh data that's flowing from Django to this I've seen a branch for Django that Django started developing an OSQL support. So how how this framework adapts that.

21:29

Speaker 2: On that level I'll say it's the same as Django. I mean if you can get a non-relational database working with Django, with the ORM That's what Messen uses with the ORM and if you can uh fake that so to speak uh it should work. I haven't really done it and Messen doesn't provide anything specific for it.

21:50

Speaker 3: Okay.

21:50

Speaker 2: But it's just whatever worked with Django We'll work in with messenger in that respect.

21:56

Speaker 3: Thank you.

21:56

Speaker 4: Does anyone else have a question? Right. Thank you for your time.

Questions this talk answers

What does Mezzanine provide out of the box for a Django content site?

Mezzanine adds content-management features such as a blog, hierarchical pages, scheduled publishing, multi-site support, search, an admin interface, and a Bootstrap-based starting theme, while retaining Django’s familiar architecture and permissions.

Discussed at 3:32

How do you install an existing Django app in Mezzanine?

Add the app to `INSTALLED_APPS`, wire its URLs into the project, and run migrations. More complex Django requirements such as custom middleware or context processors are configured in the usual Django way.

Discussed at 5:07

How can I add drafts, scheduled publishing, expiration dates, and SEO-friendly slugs to a Django model in Mezzanine?

Inherit the model from Mezzanine’s `Displayable` model. It supplies title, slug, publish date, draft/published status, scheduling and expiration fields, metadata, and related admin support.

Discussed at 8:09

How do I make a Mezzanine view show only published content?

Use Mezzanine’s published manager, such as `objects.published`, instead of `objects.all()`. You can then order the results by publish date to show the newest content first.

Discussed at 12:02

How can I make Django admin inline items sortable in Mezzanine?

Inherit the inline model from Mezzanine’s `Orderable` model and use a dynamic tabular or stacked inline admin class. This adds drag-and-drop ordering and lets administrators create additional inline forms dynamically.

Discussed at 13:37

How do I integrate my Django templates with Mezzanine’s default theme?

Extend Mezzanine’s base templates and fill the appropriate blocks, such as the title and main-content blocks. This quickly integrates the application with the default Bootstrap theme, which can still be replaced or customized.

Discussed at 15:08

Does Mezzanine support NoSQL databases?

Mezzanine does not provide special NoSQL support; it uses Django’s ORM. If a non-relational database works with Django’s ORM, it should work with Mezzanine as well, although the speaker had not personally tested it.

Discussed at 21:29

Presenters

Note: We understand that names change, people change, and bodies change. We respect each individual's journey and privacy. If you have any concerns about a video or need us to remove content, please don't hesitate to contact us. We will handle your request with care and promptly address any issues.

More videos by Ed Rivas

More videos from DjangoCon US