Gary
Gary

Reputation: 1106

How to add page templates to Wagtail after installing into an existing Django application

I'm trying to extend an already existing Django App. The app is functioning fine as is, but I would like to add blog functionality.

I've installed Wagtail, using the guidelines here (http://docs.wagtail.io/en/latest/getting_started/integrating_into_django.html) To check wagtail is installed, I have navigated to here: http://myurl/cms

And the wagtail admin panel is displayed. When I navigate to http://myurl/admin I get the default admin control panel for my Django app, so far so good.

Now I am trying to build the blog.

I found this tutorial: http://wiseodd.github.io/techblog/2015/06/22/developing-wagtail/ which suggests the following as a first step: -

First, we’ll create our generic page class as home page class is already created by default when we started Wagtail project.

It then displays this code:

# core/models.py

from wagtail.wagtailcore.models import Page
from wagtail.wagtailcore.fields import RichTextField
from wagtail.wagtailadmin.edit_handlers import FieldPanel
from wagtail.wagtailsearch import index

# We’re deriving our GenericPage from Page class, so that our GenericPage also has Page’s field, e.g. title
class GenericPage(Page):
    # Let’s create our custom field, named body which is a rich text
    body = RichTextField()

    # Index the body field, so that it will be searchable
    search_fields = Page.search_fields + (index.SearchField(‘body'),) # To show our body field in admin panel, we have to wrap it with FieldPanel and add it to Page’s field panel content_panels = Page.content_panels + [FieldPanel('body', classname=‘full’)]

I could not find which file I was meant to add this into. I searched the system using grep, and found a number of files that had the text string:

from wagtail.wagtailcore.models import Page

I decided the most likely candidate was in the directory:

env/lib/python2.7/site-packages/wagtail/project_template

Within my original app directory. I added the code above to the models.py file residing in the above directory. I then ran

python manage.py makemigrations

But it said no migrations were found. The next step in the tutorial posted above suggests you should now see three different page types available to create in the control panel, but I can not find the option to create any pages.

  1. Can you tell me if I edited the correct file above, or if I should have edited a different file, and also

  2. Why I am not seeing any option to add a new page in the wagtail control panel?

I have consulted with the documentation here (http://docs.wagtail.io/en/latest/getting_started/tutorial.html) and tried following the 'extend the homepage model' section, but couldn't figure out where the home/models.py file is as there is no folder called home in my Django app.

Thanks for any advice

Upvotes: 2

Views: 1413

Answers (1)

gasman
gasman

Reputation: 25227

As the final section of the "integrating into Django" docs says:

You’re now ready to add a new app to your Django project (via ./manage.py startapp - remember to add it to INSTALLED_APPS) and set up page models

Running ./manage.py startapp blog will add a blog app to your project, including an empty models.py - this is where you add your page definitions. (The Wagtail docs don't go into detail on this, because it's just following the standard Django workflow, which is hopefully familiar to anyone with an existing Django project to integrate with...)

Tutorials that use wagtail start my_project as a starting point will omit this step, because the starter project comes with a pre-made models.py with a HomePage model. The site-packages/wagtail/project_template directory you found is actually the 'master' copy of the starter project, which gets cloned at the point that you run wagtail start my_project. Since this isn't hooked up to your current project, changing it had no effect.

Upvotes: 2

Related Questions