Navigation Menu

Skip to content

Commit

Permalink
Update the configuration docs example to use author/blooks instead of…
Browse files Browse the repository at this point in the history
… gallery/images, and add the new options for registered settings, choices and append.
  • Loading branch information
stephenmcd committed Jun 6, 2012
1 parent 024440e commit aa95938
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions docs/configuration.rst
Expand Up @@ -21,22 +21,26 @@ each setting you want to define which takes four keyword arguments:
* ``description``: The description of the setting.
* ``editable``: If ``True``, the setting will be editable via the admin.
* ``default``: The default value of the setting.
* ``choices``: A list of choices the user can select from when the
setting is editable.
* ``append``: If registering an existing setting, the default value
given will be appended to the current.

.. note::

For settings registered with ``editable`` as ``True``, currently only
strings, integers/floats and boolean values are supported for the
``default`` value.

For example suppose we had a ``gallery`` application and we wanted to
create a setting that controls the number of photos displayed per page,
we would define the following in ``gallery.defaults``::
For example suppose we had a ``authors`` application and we wanted to
create a setting that controls the number of books displayed per author
page, we would define the following in ``authors.defaults``::

from mezzanine.conf import register_setting

register_setting(
name="GALLERY_PHOTOS_PER_PAGE",
description="The number of gallery photos to show on a single page.",
name="AUTHORS_BOOKS_PER_PAGE",
description="The number of books to show per author page.",
editable=True,
default=10,
)
Expand All @@ -52,16 +56,14 @@ which when called will cause the settings object to reload editable settings
from the database the next time an editable setting is accessed. Continuing
on from our previous example, suppose we have a view for photos::

from django.shortcuts import render_to_response
from django.template import RequestContext

from django.shortcuts import render
from mezzanine.conf import settings
from models import GalleryImage
from .models import Book

def gallery_view(request):
def books_view(request):
settings.use_editable()
photos = GalleryImage.objects.all()[:settings.GALLERY_PHOTOS_PER_PAGE]
return render_to_response("gallery.html", {"photos": photos}, RequestContext(request)})
books = Book.objects.all()[:settings.AUTHORS_BOOKS_PER_PAGE]
return render(request, "books.html", {"books": books})

When defining editable settings, care should be taken when considering
where in your project the setting will be used. For example if a setting
Expand Down

0 comments on commit aa95938

Please sign in to comment.