class silverflask.models.DataObject.DataObject

The DataObject class is the basic building block of any CMS Element. It is a mixin that provides three basic database columns:


  • id – Primary key, integer id (use for joins and relationships)
  • created_on – the datetime when the DataObject was created
  • last_modified – the datetime when the DataObject was last modified

Get object as dict. Very useful for json responses. :return: dict with all database columns

classmethod get_cms_form()

Build and return Form class.

If you want to define your custom CMS Object, you likely want to override the default CMS Form. E.g.:

from wtforms import fields
def get_cms_form(cls):
    form = super().get_cms_form()
    form.textfield = fields.StringField("Textfield")
    return form
Returns:Form Class (has to be instantiated!).


class silverflask.models.SiteTree.SiteTree

The SiteTree is the database model from which all pages have to inherit. It defines the parent/children relationships of the page tree. It also defines everything that’s needed to get nice URL slugs working.


Silverflask defines a number of mixins that can be utilized to enhance DataObjects (and are used in the SiteTree class for example).

class silverflask.mixins.OrderableMixin.OrderableMixin

A mixin that makes a DataObject sortable by adding a sort_order database field. Classes with this mixin automatically keep the sort_order in sync.

classmethod check_duplicates()

Check the table for duplicates and if there are duplicates reindex :return: nothing


Sort element to the end

insert_after(index, orderable_base_class=None, index_absolute=True, query=None)

Inser after index variable

  • index – index (this is the sort_order variable of the element that you want to insert after!)
  • orderable_base_class – baseclass (useful in certain circumstances e.g. gridfields)



Move current DataObject after index (= sort_order) of another element

Parameters:index – obj element where to move after or sort order of other elements
classmethod reindex()

Reindexes the table.

The sort order field can have “jumps” in it (e.g. 1, 4, 5, 8, 9) and reindex brings that back to a linearly ascending order: (1,2,3,4...)

class silverflask.mixins.VersionedMixin.VersionedMixin

A mixin that adds versioning support to DataObjects. It adds a new live table that saves the object on a publish operation, a new query_live operator that queries the live versions of the object and a versions relationship that saves all versions of this object (a version is automatically created on a save operation).


Override this function to control who is allowed to publish pages in the CMS :return: Boolean (True if allowed to publish)


Create a copy of the current draft to the live table and publish this DataObject (make it visible to the outside world). :return: empty


class silverflask.models.User.User(username, password, email=None, is_enabled=True)

The base User model. Defines the following fields:

username = String, and unique, firstname, lastname = String

email = String, unique

The password is set with user.set_password(“password”), and then stored with encryption.


The file objects reflect the file items uploaded through the CMS. ImageObject is an inherited class which implements common image functionality, such as cropping and resizing.

class silverflask.models.FileObject.FileObject(file=None, location=None, folder=None)

Contains file information

  • location – Location of the file
  • name – Name of the file (usually filename without extension)
  • type – Contains

Delete this file also from disk.


Return the url for this file (handled by the FileStorageBackend

class silverflask.models.FileObject.ImageObject(file=None, location=None, folder=None)

A basic ImageObject, that inherits all properties from the file object and adds some functionality related to images, such as cropping and resizing, as well as caching the cropped and/or resized images.

resize(width=None, height=None, mode='crop', background='white')

Resize image

  • width – define width in pixels
  • height – height in pixels. If no height is set, it will be set to width (i.e. the result will be a square)
  • mode – string, one of ‘crop’ (default), ‘pad’, ‘fit’ or ‘reshape’
  • background – background color, as string (i.e. ‘blue’ or hex ‘#F0F000’). As supported by the ImageColor module of Pillow.


The FileStorageBackend is a class that abstracts away the underlying file storage. At the moment, the only implemented backend is the LocalFileStorageBackend which implements methods to save files to the local flask installation (defaults to the /static/uploads/ folder).

Another FileStorageBackend could, for example, be an implementation for a S3 Backend (e.g. using the boto library).