Multiple Blogs

206 views
Skip to first unread message

Dennis Kioko

unread,
Feb 28, 2015, 5:48:47 AM2/28/15
to mezzani...@googlegroups.com
I'm trying to set up multiple blogs - "blog" and "news".

I have tried various tricks, such as using "news" for "blog/category/news", but I'm looking for a way in which the two would be treated as different blogs, as I plan to also implement a news ticker for "news". I see the blog app allows multiple blogs, but I have not had much luck setting up the same in Mezzanine. 

Any pointers to the most efficient way to do this? 

Eduardo Rivas

unread,
Mar 2, 2015, 10:03:33 PM3/2/15
to mezzani...@googlegroups.com
Hello Dennis. I actually needed to do this for a project a few years ago. As far a I know, Mezzanine doesn't support multiple blogs out of the box. What I did was create a "Blog" model, which simply had a slug and title, and then add it as FK to the standard BlogPost and BlogCategory models. After that, it's just a matter of updating urls and views to account for a blog_slug parameter to get the correct Blog instance. If you want to get fancy, you can create "base" templates for each blog. That way, you get unique blog posts, categories and templates for each blog. You'll also need to modify the queries made by the Admin to only return the subset of BlogPost's that match a Blog instance in particular.

Important note: this of course implies you're "forking" Mezzanine's blog app, so you will have to maintain it by yourself and install it in place of the default one.

Josh Cartmell

unread,
Mar 4, 2015, 10:50:03 AM3/4/15
to mezzani...@googlegroups.com
Dennis, another option would be to just use Blog Categories for your different "blogs"

You could also change the Blog slug to something more generic like "posts".  Then you could have your blog at:

On Mon, Mar 2, 2015 at 10:03 PM, Eduardo Rivas <jeriva...@gmail.com> wrote:
Hello Dennis. I actually needed to do this for a project a few years ago. As far a I know, Mezzanine doesn't support multiple blogs out of the box. What I did was create a "Blog" model, which simply had a slug and title, and then add it as FK to the standard BlogPost and BlogCategory models. After that, it's just a matter of updating urls and views to account for a blog_slug parameter to get the correct Blog instance. If you want to get fancy, you can create "base" templates for each blog. That way, you get unique blog posts, categories and templates for each blog. You'll also need to modify the queries made by the Admin to only return the subset of BlogPost's that match a Blog instance in particular.

Important note: this of course implies you're "forking" Mezzanine's blog app, so you will have to maintain it by yourself and install it in place of the default one.

--
You received this message because you are subscribed to the Google Groups "Mezzanine Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mezzanine-use...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Dennis Kioko

unread,
Mar 9, 2015, 10:32:54 AM3/9/15
to mezzani...@googlegroups.com
I decided to go with Josh's suggestion as it is easier when it comes to maintenance (and of course now that the client wanted it yesterday :-) ). Also found the "Category_Link" extensions that makes it easy to maintain different blog categories resulting in "news" and "blog" pages. 

userblaz

unread,
Oct 7, 2016, 2:59:02 AM10/7/16
to Mezzanine Users
Hi Dennis,

wandering how it is working out with the categories as different blogs.. is it working fine? are you able to style differently the posts from separate categories? Cheers

Ken Bolton

unread,
Oct 7, 2016, 10:16:33 AM10/7/16
to mezzanine-users
Hi,

Both ways mentioned in this thread are pretty standard Mezzanine Way approaches to multiple blogs with separate styles. Josh's suggestion is a good place to start and could be refactored to become Eduardo's suggestion.

To unsubscribe from this group and stop receiving emails from it, send an email to mezzanine-users+unsubscribe@googlegroups.com.

userblaz

unread,
Jan 3, 2017, 9:54:13 AM1/3/17
to Mezzanine Users
Hi Kenneth,

can you suggest how can I style differently the 2 blogs if I want to use Josh's approach?

Ken Bolton

unread,
Jan 3, 2017, 12:33:20 PM1/3/17
to mezzanine-users
What have you tried so far? Josh's blog on styling mezzanine is where I would start.

-ken

To unsubscribe from this group and stop receiving emails from it, send an email to mezzanine-users+unsubscribe@googlegroups.com.

userblaz

unread,
Jan 3, 2017, 2:30:58 PM1/3/17
to Mezzanine Users
I went through Josh's blog and it was very helpful with the restyle of my site but i didn't see any section explaining how to have different stylings for 2 or more different blogs. the base template is the same, I want to have a different base.html template on http://example.com/posts/category/blog/ than http://example.com/posts/category/news/...

Ken Bolton

unread,
Jan 3, 2017, 3:47:41 PM1/3/17
to mezzanine-users

On Tue, Jan 3, 2017 at 2:30 PM, userblaz <user...@gmail.com> wrote:
>
> I went through Josh's blog and it was very helpful with the restyle of my site but i didn't see
> any section explaining how to have different stylings for 2 or more different blogs. the base 
> template is the same, I want to have a different base.html template on
The crux of one solution is to add something appropriate to your blog_post_list.html and blog_post_detail.html, perhaps in `extra_head` block, that has your custom CSS in it with template `if` blocks to check the category.

userblaz

unread,
Jan 4, 2017, 4:00:03 PM1/4/17
to Mezzanine Users
thanks I managed with {% if category.title == 'blog' %}..

Ken Bolton

unread,
Jan 4, 2017, 4:11:59 PM1/4/17
to mezzanine-users
category.slug might be better for you!

--
You received this message because you are subscribed to the Google Groups "Mezzanine Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mezzanine-users+unsubscribe@googlegroups.com.

Eduardo Rivas

unread,
Jan 4, 2017, 4:16:50 PM1/4/17
to Mezzanine Users
It looks like Mezzanine will derive a template name from the category slug, allowing you to create one template per category. Just an alternative to the in-template conditional.

https://github.com/stephenmcd/mezzanine/blob/master/mezzanine/blog/views.py#L46-L47
To unsubscribe from this group and stop receiving emails from it, send an email to mezzanine-use...@googlegroups.com.

userblaz

unread,
Jan 6, 2017, 6:19:55 PM1/6/17
to Mezzanine Users
actually in some cases category.title worked and category.slug did not... 

do you guys know if is possible to filter blog_recent_posts with the category? for example to display only the recent posts of that particular category..

Amir

unread,
Aug 9, 2018, 9:48:04 AM8/9/18
to Mezzanine Users
This suggestion of yours is remarkable Eduardo and I am craving to have multiple and separated blogs. I am a bit new to Django though, Could you elaborate more on the details please? I could open a topic on StackOverflow if you would prefer. This would be a huge help bro. 

Eduardo Rivas

unread,
Aug 10, 2018, 2:18:27 PM8/10/18
to mezzani...@googlegroups.com

Sorry, don’t have enough time to write a code sample right now, but here is a more detailed description of the steps:

 

  • Create a new application with all the contents copied from mezzanine.blog. Let’s call it multiblog. Add it to installed apps.
  • In models.py add a new Blog model inheriting from Slugged (this will give it a title and slug). Register it in the admin so you can add Blog instances.
  • Add foreign keys to this new Blog model to BlogPost and BlogCategory, so each post and category will belong to one blog. Create the required migrations. Make sure you expose the FK field in the admin so each post and category can choose to which Blog they will belong to.
  • Rewrite urls.py to account for the Blog slug. For example: “/blog/some-post” becomes “/blog/blog-slug/some-post”. The regex for the URL should capture the blog slug so it will be passed to the view.
  • Rewrite views.py to account for the new blog slug, and modify the querysets to only look into the posts / categories for a particular blog. Something like BlogPost.objects.filter(blog__slug=<captured slug>).
  • Optionally rewrite the template-finding logic in the view to allow you to use different (per-blog) templates. For example, you could have the view load templates by looking inside folders that match the blog slug, like “templates/blog/<variable slug>/blog_post_detail.html” and “templates/blog/<variable slug>/blog_post_list.html”.

 

Hope that helps!

--
You received this message because you are subscribed to a topic in the Google Groups "Mezzanine Users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/mezzanine-users/LFhT0oryfEI/unsubscribe.
To unsubscribe from this group and all its topics, send an email to mezzanine-use...@googlegroups.com.

Jesper Joachim Sørensen

unread,
Jun 2, 2019, 5:44:59 AM6/2/19
to Mezzanine Users
Hey Eduardo, and thanks for your inputs on multiple blogs. I am currently creating a multiple blog for a primary schcool with a blog for each grade. I am following your suggestions on the steps to follow in mezzanine.
However the first point about copying all the the contents from mezzanine.blog made me a little confused. Normally I just copy one a file at a time to my blog app (eg. the blog_post_deatil.html) and then modifies this file, and then it will overwrite the blog_post_deatil.html in mezzanine.blog.
However for the models I think it's different. I tried to copy the content of the models.py from mezzanine.blog to my blog app (same procedure as with the blog_post_deatil.html) but that throws me an error (something about a duplicate). So when you say copying all the contents from mezzanine.blog, do you also mean the models.py and how without getting an error?
Kind regards, Jesper

To unsubscribe from this group and all its topics, send an email to mezzani...@googlegroups.com.

Eduardo Rivas

unread,
Jun 3, 2019, 12:26:09 PM6/3/19
to mezzani...@googlegroups.com

Hi Jesper.

 

That’s correct, you’ll need to copy the entire mezzanine.blog folder. You’ll also need to replace all mentions of it with your own version on settings.py and urls.py.

 

You’re essentially creating your own blog app to replace the one that ships with Mezzanine.

--

You received this message because you are subscribed to the Google Groups "Mezzanine Users" group.

To unsubscribe from this group and stop receiving emails from it, send an email to mezzanine-use...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/mezzanine-users/e0d65396-96ce-462b-acc7-796bed6d3088%40googlegroups.com.

Reply all
Reply to author
Forward
0 new messages