entity_admin — Camelot documentation

### Navigation

- index
- modules |
- next |
- previous |
- Camelot documentation »
- Camelot API »
- admin »

# entity_admin

class `camelot.admin.entity_admin.` `EntityAdmin`(app_admin, entity)

  Admin class specific for classes that are mapped by sqlalchemy. This allows for much more introspection than the standard `camelot.admin.object_admin.ObjectAdmin`.

  It has additional class attributes that customise its behaviour.

  Basic

  `list_action`

    The `camelot.admin.action.Action` that will be triggered when the user selects an item in a list of objects. This defaults to `camelot.admin.action.list_action.OpenFormView`, which opens a form for the current object.

  Filtering

  `list_filter`

    A list of fields that should be used to generate filters for in the table view. If the field named is a one2many, many2one or many2many field, the field name should be followed by a field name of the related entity

        class Project(Entity):
            oranization = OneToMany('Organization')
            name = Field(Unicode(50))

          class Admin(EntityAdmin):
              list_display = ['organization']
              list_filter = ['organization.name']

  Copying

  `copy_deep`

    A dictionary of fields that will be deep copied when the user presses the copy button. This is usefull for OneToMany fields. The key in the dictionary should be the name of the field, and the value is a new dictionary that can contain other fields that need to be copied:

        copy_deep = {'addresses':{}}

  `copy_exclude`

    A list of fields that should not be copied when the user presses the copy button:

        copy_exclude = ['name']

    The fields that form the primary key of the object will be excluded by default.

  Searching

  `list_search`

    A list of fields that should be searched when the user enters something in the search box in the table view. By default all fields are searched for which Camelot can do a conversion of the entered string to the datatype of the underlying column.

    For use with one2many, many2one or many2many fields, the same rules as for the list_filter attribute apply

  `search_all_fields`

    Defaults to True, meaning that by default all searchable fields should be searched. If this is set to False, one should explicitely set the list_search attribute to enable search.

  `expanded_list_search`

    A list of fields that will be searchable through the expanded search. When set to None, all the fields in list_display will be searchable. Use this attribute to limit the number of search widgets. Defaults to None.

  `copy`(*args, **kwargs)

    Duplicate an object. If no new object is given to copy to, a new one will be created. This function will be called every time the user presses a copy button.

    Parameters: | obj – the object to be copied from new_obj – the object to be copied to, defaults to None
    Returns: | the new object

    This function takes into account the deep_copy and the copy_exclude attributes. It tries to recreate relations with a minimum of side effects.

  `create_select_view`(*args, **kwargs)

    Returns a Qt widget that can be used to select an element from a query

    Parameters: | query – sqlalchemy query object parent – the widget that will contain this select view, the

    returned widget has an entity_selected_signal signal that will be fired when a entity has been selected.

  `create_table_view`(*args, **kwargs)

    Returns a QWidget containing a table view

  `delete`(*args, **kwargs)

    Delete an entity instance

  `expunge`(*args, **kwargs)

    Expunge the entity from the session

  `flush`(*args, **kwargs)

    Flush the pending changes of this entity instance to the backend

  `get_dynamic_field_attributes`(obj, field_names)

    Takes the dynamic field attributes from through the ObjectAdmin its get_dynamic_field_attributes and add the new_message attributes for One2Many fields where the object was not flushed yet

  `get_expanded_search_fields`(*args, **kwargs)

    Returns: | a list of tuples of type [(field_name, field_attributes)]

  `get_field_attributes`(*args, **kwargs)

    Get the attributes needed to visualize the field field_name :param field_name: the name of the field

    Returns: | a dictionary of attributes needed to visualize the field,

    those attributes can be:
      - python_type : the corresponding python type of the object
      - editable : bool specifying wether the user can edit this field
      - widget : which widget to be used to render the field
      - ...
  `get_filters`(*args, **kwargs)

    Returns the filters applicable for these entities each filter is

    Returns: | [(filter_name, [(option_name, query_decorator), ...), ... ]

  `get_query`(*args, **kwargs)

    Returns: | an sqlalchemy query for all the objects that should be

    displayed in the table or the selection view. Overwrite this method to change the default query, which selects all rows in the database.

  `is_deleted`(*args, **kwargs)

    Returns: | True if the object has been deleted from the persistent

    state, False otherwise

  `is_persistent`(*args, **kwargs)

    Returns: | True if the object has a persisted state, False otherwise

  `refresh`(*args, **kwargs)

    Undo the pending changes to the backend and restore the original state

  `set_defaults`(*args, **kwargs)

    Set the fields of an object to their default state.

    Parameters: | include_nullable_fields – also set defaults for nullable fields, depending on the context, this should be set to False to allow the user to set the field to None

  `validator`

    alias of `EntityValidator`

### Navigation

- index
- modules |
- next |
- previous |
- Camelot documentation »
- Camelot API »
- admin »

Comments
blog comments powered by Disqus