entity_admin¶
- class camelot.admin.entity_admin.EntityAdmin(app_admin, entity)[source]¶
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.
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 = Column( 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 useful for OneToMany fields. The key in the dictionary should be the name of the field, and the value is a new dictionary
copy_deep = {'addresses':{}}
This dictionary can contain fields in the related object that need to be deep copied as well
copy_deep = {'addresses':{'city':{}}}
- 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.
To further customize the copy process without additional user interaction, camelot.admin.object_admin.EntityAdmin.copy() method can be overwritten.
If the user interaction during the copy process needs to be customized as well, the camelot.admin.action.list_action.DuplicateSelection class can be subclassed and used as a custom action.
- add(obj)[source]¶
Adds the entity instance to the default session, if it is not yet attached to a session
- copy(obj, new_obj=None)[source]¶
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.
- get_all_fields_and_attributes()[source]¶
In addition to all the fields that are defined in the views or through the field_attributes, this method returns all the fields that have been mapped.
- get_descriptor_field_attributes(field_name)[source]¶
Returns a set of default field attributes based on introspection of the descriptor of a field.
- get_dynamic_field_attributes(obj, field_names)[source]¶
Takes the dynamic field attributes from through the ObjectAdmin its get_dynamic_field_attributes and make relational fields not editable in case the object is not yet persisted.
- get_expanded_search_filters()[source]¶
Returns: a list of tuples of type [(field_name, field_attributes)]
- get_filters()[source]¶
Returns the filters applicable for these entities each filter is
Returns: [filter, filter, ...]
- get_modifications(obj)[source]¶
Get the modifications on an object since the last flush. :param obj: the object for which to get the modifications :return: a dictionary with the changed attributes and their old
value
- get_query()[source]¶
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.
- get_search_fields(substring)[source]¶
Generate a list of fields in which to search. By default this method returns the fields in the list_search attribute as well as the properties that are mapped to a column in the database. Any property that is not a simple Column might result in very slow searches, so those should be put explicitly in the list_search attribute.
Parameters: substring – that part of the complete search string for which the search fields are requested. This allows analysis of the search string to improve the search behavior Returns: a list with the names of the fields in which to search
- classmethod get_sql_field_attributes(columns)[source]¶
Returns a set of default field attributes based on introspection of the SQLAlchemy columns that form a field
Param: columns a list of sqlalchemy.schema.Column objects. Returns: a dictionary with field attributes By default this method looks at the first column that defines the field and derives a delegate and other field attributes that make sense.
- is_deleted(obj)[source]¶
Returns: True if the object has been deleted from the persistent state, False otherwise
- primary_key(obj)[source]¶
Get the primary key of an object :param obj: the object to get the primary key from :return: a tuple with with components of the primary key, or none
if the object has no primary key yet or any more.
- refresh(entity_instance)[source]¶
Undo the pending changes to the backend and restore the original state
- validator¶
alias of EntityValidator