Config

Model configuration

class trionyx.config.ModelConfig(model: Type[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(ModelConfig):
        verbose_name = '{name}'
        list_default_fields = ['id', 'created_at', 'name']
        list_search_fields = ['name', 'description']
menu_name = None

Menu name, default is model verbose_name_plural

menu_order = None

Menu order

menu_exclude = False

Exclude model from menu

menu_root = False

Add menu item to root instead of under the app menu

menu_icon = None

Menu css icon, is ony used when root menu item

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 prefetch for query, use this for relations that are used in search or renderer

list_default_sort = '-pk'

Default sort field for list view

list_update_queryset = None

Function to update queryset

api_fields = None

Fields used in API POST/PUT/PATCH methods, fallback on fields used in create and edit forms

api_description = None

Description text that is shown in the API documentation

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
header_buttons = None

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, context: context.get('page') == 'view', # Function that gives True or False if button must be displayed
       'dialog': True,
       'dialog_options': """function(data, dialog){
           // Example that will close dialog on success
           if (data.success) {
               dialog.close();
           }
       }"""
   }
]
display_add_button = True

Display add button for this model

display_change_button = True

Display change button for this model

display_delete_button = True

Display delete button for this model

disable_view = False

Disable view for this model

disable_add = False

Disable add for this model

disable_change = False

Disable change for this model

disable_delete = False

Disable delete for this model

admin_view_only = False

Only admins can view this model

admin_add_only = False

Only admins can add this model

admin_change_only = False

Only admins can change this model

admin_delete_only = False

Only admins can delete 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

get_app_verbose_name(title: bool = True) → str[source]

Get app verbose name

get_verbose_name(title: bool = True) → str[source]

Get class verbose name

get_verbose_name_plural(title: bool = True) → str[source]

Get class plural verbose name

is_trionyx_model

Check if config is for Trionyx model

has_config(name: str) → bool[source]

Check if config is set

has_permission(action, obj=None, user=None)[source]

Check if action can be performed on object

get_field(field_name)[source]

Get model field by name

get_fields(inlcude_base: bool = False, include_id: bool = False)[source]

Get model fields

get_url(view_name: str, model: django.db.models.base.Model = None, code: str = None) → str[source]

Get url for model

get_absolute_url(model: django.db.models.base.Model) → str[source]

Get model url

get_list_fields() → List[dict][source]

Get all list fields

get_field_type(field: django.db.models.fields.Field) → str[source]

Get field type base on model field class

get_header_buttons(obj=None, context=None)[source]

Get header buttons for given page and object