Code fixes and clarifications for tutorial - fixes #1473

pull/1479/merge
Matt Westcott 2015-07-07 15:33:44 +01:00
rodzic 82171f70fa
commit fbb153fbe4
1 zmienionych plików z 26 dodań i 20 usunięć

Wyświetl plik

@ -48,13 +48,14 @@ Your first Wagtail site
Extend the HomePage model
-------------------------
Out of the box you get a blank ``HomePage`` model and the "home" app has a
migration that creates a homepage and configures Wagtail to use it.
Out of the box, the "home" app defines a blank ``HomePage`` model in ``models.py``, along with a migration that creates a homepage and configures Wagtail to use it.
This example extends the HomePage model to add a body field.
Edit ``home/models.py`` as follows, to add a ``body`` field to the model:
.. code:: python
from __future__ import unicode_literals
from django.db import models
from wagtail.wagtailcore.models import Page
@ -66,30 +67,32 @@ This example extends the HomePage model to add a body field.
body = RichTextField(blank=True)
content_panels = Page.content_panels + [
FieldPanel('body')
FieldPanel('body', classname="full")
]
``body`` is defined as ``RichTextField``, a special Wagtail field. You
can use any of the `Django core fields <https://docs.djangoproject.com/en/1.8/ref/models/fields/>`__. ``content_panels`` define the
capabilities and the layout of the editing interface. :doc:`More on creating Page models. <../topics/creating_pages>`
Run ``python manage.py makemigrations``, then
``python manage.py migrate`` to update the database with your model
changes. You must run the above commands each time you make changes to
the model definition.
To reflect the model changes, edit
``core/templates/core/home_page.html``. Wagtail uses normal Django
templates to render each page type. It automatically generates a
suggestion by separating capital letters with underscores (e.g. HomePage
becomes home\_page.html).
You can now edit the homepage within the Wagtail admin area (go to Explorer, Homepage, then Edit) to see the new Body field. Enter some text into the body field, and publish the page.
The page template now needs to be updated to reflect the changes made
to the model. Wagtail uses normal Django templates to render each page
type. It automatically generates a template filename from the model name
by separating capital letters with underscores (e.g. HomePage becomes
home\_page.html). Edit
``home/templates/home/home_page.html`` to contain the following:
.. code:: html+django
{% extends "base.html" %}
{% load static core_tags wagtailcore_tags %}
{% load wagtailcore_tags %}
{% block body_class %}template-homepage{% endblock %}
@ -108,7 +111,7 @@ We are now ready to create a blog. To do so, run
Add the new ``blog`` app to ``INSTALLED_APPS`` in ``mysite/settings/base.py``.
The following example defines a basic blog post model in ``blog/models.py``
The following example defines a basic blog post model in ``blog/models.py``:
.. code:: python
@ -142,7 +145,7 @@ Create a template at ``blog/templates/blog/blog_page.html``:
{% extends "base.html" %}
{% load static core_tags wagtailcore_tags %}
{% load wagtailcore_tags %}
{% block body_class %}templage-blogpage{% endblock %}
@ -152,7 +155,7 @@ Create a template at ``blog/templates/blog/blog_page.html``:
<div class="intro">{{ self.intro }}</div>
{{ self.body | richtext }}
{{ self.body|richtext }}
{% endblock %}
Run ``python manage.py makemigrations`` and ``python manage.py migrate``.
@ -204,13 +207,15 @@ model:
FieldPanel('body'),
]
Run ``python manage.py makemigrations`` and ``python manage.py migrate``.
Adjust your blog page template to include the image:
.. code:: html+django
{% extends "base.html" %}
{% load static core_tags wagtailcore_tags wagtailimages_tags %}
{% load wagtailcore_tags wagtailimages_tags %}
{% block body_class %}templage-blogpage{% endblock %}
@ -224,7 +229,7 @@ Adjust your blog page template to include the image:
<div class="intro">{{ self.intro }}</div>
{{ self.body | richtext }}
{{ self.body|richtext }}
{% endblock %}
.. figure:: ../_static/images/tutorial/tutorial_6.png
@ -255,14 +260,14 @@ The above creates an index type to collect all our blog posts.
{% extends "base.html" %}
{% load static core_tags wagtailcore_tags %}
{% load wagtailcore_tags %}
{% block body_class %}template-blogindexpage{% endblock %}
{% block content %}
<h1>{{ self.title }}</h1>
<div class="intro">{{ self.intro }}</div>
<div class="intro">{{ self.intro|richtext }}</div>
{% endblock %}
Related items
@ -335,6 +340,7 @@ can be BlogPages or external links. Change ``blog/models.py`` to
intro = RichTextField(blank=True)
content_panels = Page.content_panels + [
FieldPanel('intro', classname="full"),
InlinePanel('related_links', label="Related links"),
]
@ -347,14 +353,14 @@ Extend ``blog_index_page.html`` to show related items
{% extends "base.html" %}
{% load static core_tags wagtailcore_tags %}
{% load wagtailcore_tags %}
{% block body_class %}template-blogindexpage{% endblock %}
{% block content %}
<h1>{{ self.title }}</h1>
<div class="intro">{{ self.intro }}</div>
<div class="intro">{{ self.intro|richtext }}</div>
{% if self.related_links.all %}
<ul>