Admin classes

The Admin classes are the classes that specify how objects should be visualized, they define the look, feel and behaviour of the Application. Most of the behaviour of the Admin classes can be tuned by changing their class attributes. This makes it easy to subclass a default Admin class and tune it to your needs.

../_images/admin_classes.png

ObjectAdmin

Camelot is able to visualize any Python object, through the use of the camelot.admin.object_admin.ObjectAdmin class. However, subclasses exist that use introspection to facilitate the visualisation.

Each class that is visualized within Camelot has an associated Admin class which specifies how the object or a list of objects should be visualized.

Usually the Admin class is bound to the model class by defining it as an inner class of the model class:

class Options(object):
    """A python object in which we store the change in rating
    """
    
    def __init__(self):
        self.only_selected = True
        self.change = 1

    # Since Options is a plain old python object, we cannot
    # use an EntityAdmin, and should use the ObjectAdmin            
    class Admin( ObjectAdmin ):
        verbose_name = _('Change rating options')
        form_display = ['change', 'only_selected']
        form_size = (100, 100)
        # Since there is no introspection, the delegate should
        # be specified explicitely, and set to editable
        field_attributes = {'only_selected':{'delegate':delegates.BoolDelegate,
                                             'editable':True},
                            'change':{'delegate':delegates.IntegerDelegate,
                                      'editable':True},
                            }

# begin change rating action definition

Most of the behaviour of the Admin class can be customized by changing the class attributes like verbose_name, list_display and form_display.

Other Admin classes can inherit ObjectAdmin if they want to provide additional functionallity, like introspection to set default field attributes.

EntityAdmin

The camelot.admin.entity_admin.EntityAdmin class is a subclass of ObjectAdmin that can be used to visualize objects mapped to a database using SQLAlchemy.

The EntityAdmin uses introspection of the model to guess the default field attributes. This makes the definition of an Admin class less verbose.

class Tag(Entity):

    __tablename__ = 'tags'

    name = Column( sqlalchemy.types.Unicode(60), nullable = False )
    movies = ManyToMany( 'Movie',
                         tablename = 'tags_movies__movies_tags',
                         local_colname = 'movies_id',
                         remote_colname = 'tags_id' )

    def __unicode__( self ):
        return self.name

    class Admin( EntityAdmin ):
        form_size = (400,200)
        list_display = ['name']

# begin visitor report definition

The camelot.admin.entity_admin.EntityAdmin provides some additonal attributes on top of those provided by camelot.admin.object_admin.ObjectAdmin, such as list_filter and list_search

Table Of Contents

Previous topic

Views

Next topic

Field Attributes

This Page