1

I have an existing website that is a Django App. I have installed Wagtail, and the Wagtail CMS is now accessible at www.example.com/cms. Wagtail is working correctly with my database, and all the existing users are visible when I go to settings and then users, in the wagtail CMS admin page.

I want to use Wagtail to add blog functionality to my website.

Requirements

  1. I want any user to be able to create a new blog and add posts to their blog.
  2. I want the blog created by a user to be visible at www.example.com/blogs/username/

How can I set Wagtail up to accomplish this?

I have checked the documentation at http://docs.wagtail.io/en/v1.9/ but could not figure out where to start with my modifications. I have also installed the example blog project (https://github.com/wagtail/wagtaildemo) but I was also unable to figure out how to accomplish 1 and 2 above from this.

Any complete answers, or general pointers, very welcome.

Gary
  • 1,086
  • 2
  • 13
  • 39
  • have you check the getting start tutorial? It uses a blog app as an example http://docs.wagtail.io/en/v1.9/getting_started/tutorial.html – micebrain Mar 29 '17 at 14:53
  • @micebrain Hi there thanks for the advice, yes I have, what I'm trying to understand right now is how I can make each users blog appear at `www.example.com/blogs/username/` and how I can enable every user to create a blog, for example, should every user (login via the CMS admin), this seems to present too much access, e.g. settings / users, which I wouldn't want every user to have access to, I would just like them to be able to create a blog, and add posts to it. Or have a default blog for each and every user, and have them add posts to it, that show up there `www.example.com/blogs/username/` – Gary Mar 29 '17 at 15:17
  • The blogs are going to be available for members of the public that are registered on the site to create, so I just want them to have access to the blog functionality. – Gary Mar 29 '17 at 15:19
  • So effectively something like blogger type functionality? – zglin Mar 29 '17 at 15:33
  • @zhiqiat Yes pretty much exactly (although the site is not primarily a blogging platform) we just want to give users the ability to create a blog if they want to do so. The rest of the site is already made, so I don't need the CMS for pages etc, just to create this blog functionality. – Gary Mar 29 '17 at 15:34

1 Answers1

4

The permission model built into Wagtail supports this kind of setup: http://docs.wagtail.io/en/stable/topics/permissions.html

After creating the index page for a blog, you'd create a group (Settings -> Groups in the Wagtail admin) for that blog - possibly just containing a single user - and under the 'Page permissions' section, assign it 'add' and 'publish' permission on that index page. Permissions propagate down the tree from that point, and 'add' permission encompasses the ability to edit pages that you've created yourself, so this would have the effect of giving the user control over the subpages of their blog.

This doesn't quite match the setup you've described, since it involves an existing Wagtail admin user having to do the initial setup, rather than users creating their own blog. However, since all of this configuration is done internally by creating / updating standard Django models such as Group and PagePermission, it would be possible in principle to script this process - for example, you could implement a Django view for "Set up my blog" on your site front-end, which runs the following steps:

  • Create a BlogIndexPage under /blogs with a title/slug matching request.user.username (see https://stackoverflow.com/a/43041179/1853523 for how to create pages programmatically)
  • Create a user group (django.contrib.auth.models.Group) for the current user, and assign them wagtailadmin.access_admin permission (so that they can log in to Wagtail admin)
  • Create a wagtailcore.PagePermission object corresponding to the newly-created group and blog index page, and 'add' permission; and likewise for 'publish' permission
gasman
  • 23,691
  • 1
  • 38
  • 56
  • Thanks for your very detailed and useful reply, am sure it will keep me busy for a while now I have exactly the right direction I need to head, sure others will find it useful too, thanks very much – Gary Mar 29 '17 at 20:39