Config¶
Model configuration¶
-
class
trionyx.config.
ModelConfig
(model: django.db.models.base.Model, MetaConfig=None)[source]¶ ModelConfig holds all config related to a model that is used for trionyx functionality.
Model configs are auto loaded from the apps config file. In the apps config class create a class with same name as model and set appropriate config as class attribute.
# apps.blog.apps.py class BlogConfig(BaseConfig): ... # Example config for Category model class Category: verbose_name = '{name}' list_default_fields = ['id', 'created_at', 'name'] list_search_fields = ['name', 'description']
Menu name, default is model verbose_name_plural
Menu order
Exclude model from menu
Add menu item to root instead of under the app menu
Menu css icon, is ony used when root menu item
-
global_search
= True¶ Enable global search for model
-
disable_search_index
= False¶ Disable search index, use full for model with no list view but with allot of records
-
search_fields
= ()¶ Fields to use for searching, default is all CharField and TextField
-
search_exclude_fields
= ()¶ Fields you don’t want to use for search
-
search_title
= None¶ Search title of model works the same as verbose_name, defaults to __str__. Is given high priority in search and is used in global search
-
search_description
= None¶ Search description of model works the same as verbose_name, default is empty, Is given medium priority and is used in global search page
-
list_fields
= None¶ Customise the available fields for model list view, default all model fields are available.
list_fields is an array of dict with the field description, the following options are available:
- field: Model field name (is used for sort and getting value if no renderer is supplied)
- label: Column name in list view, if not set verbose_name of model field is used
- renderer: function(model, field) that returns a JSON serializable date, when not set model field is used.
list_fields = [ { 'field': 'first_name', 'label': 'Real first name', 'renderer': lambda model field: model.first_name.upper() } ]
-
list_default_fields
= None¶ Array of fields that default is used in form list
Array of fields to add foreign-key relationships to query, use this for relations that are used in search or renderer
-
list_default_sort
= '-pk'¶ Default sort field for list view
-
api_fields
= None¶ Fields used in API model serializer, fallback on fields used in create and edit forms
-
api_disable
= False¶ Disable API for model
-
verbose_name
= '{model_name}({id})'¶ Verbose name used for displaying model, default value is “{model_name}({id})”
- format can be used to get model attributes value, there are two extra values supplied:
- app_label: App name
- model_name: Class name of model
List with button configurations to be displayed in view header bar
view_header_buttons = [ { 'label': 'Send email', # string or function 'url': lambda obj : reverse('blog.post', kwargs={'pk': obj.id}), # string or function 'type': 'default', 'show': lambda obj, alias : True, # Function that gives True or False if button must be displayed 'modal': True, } ]
-
disable_add
= False¶ Disable add for this model
-
disable_change
= False¶ Disable change for this model
-
disable_delete
= False¶ Disable delete for this model
-
auditlog_disable
= False¶ Disable auditlog for this model
-
auditlog_ignore_fields
= None¶ Auditlog fields to be ignored
-
hide_permissions
= False¶ Dont show model in permissions tree, prevent clutter from internal models
-
is_trionyx_model
¶ Check if config is for Trionyx model