Admin blocks — Django Building Blocks documentation

# Admin blocks

- Bases

- Implementations

- Utils

Admin blocks hold values for django admin fields for various models. As we follow a compositions model for defining our data models, we have created a parallel system to build django admin panels for the composition models. Optimized for mixing, matching and combining django admin config for various models.

## Bases

class building_blocks.admin.blocks.base.BaseAdminBlock

  BaseAdminBlock is the base class for creating custom admin blocks. It provides a set of fields and methods that can be overridden and extended to create custom behavior and appearance for the admin interface.

  Corresponds to django.contrib.admin.BaseModelAdmin.

  Parameters

    - base_fields – A list of fields to be displayed in the admin interface.

    - extra_fields – A list of extra/optional fields to be displayed in the admin interface.

    - admin_fields – fields that should be always included in the admin fieldset

    - extra_admin_fields – extra/optional fields that should be always included in the admin fieldset

    - readonly_fields – fields that should be always readonly in the admin form

    - extra_readonly_fields – fields that should be readonly in the admin form, but optionally

    - edit_readonly_fields – fields that should be always readonly in the admin form when editing an existing object

    - extra_edit_readonly_fields – fields that should be readonly in the admin form when editing an existing object, but optionally

    - autocomplete_fields – fields that should use autocomplete widgets in the admin form

    - extra_autocomplete_fields – fields that should use autocomplete widgets in the admin form, but optionally

class building_blocks.admin.blocks.base.AdminBlock

  Bases: `BaseAdminBlock`

  AdminBlock is used to configure views for the admin interface. It inherits from BaseAdminBlock and contains fields for django admin list view config.

  Corresponds to django.contrib.admin.ModelAdmin. Usually contains config for list views over BaseAdminBlock

  Parameters

    - actions – A list of predefined actions that can be performed on selected objects in the admin list view.

    - extra_actions – A list of extra/optional actions that can be performed on selected objects in the admin list view.

    - search_fields – A list of fields to be searched when the user enters a search query in the admin list view.

    - extra_search_fields – A list of extra/optional fields to be searched when the user enters a search query in the admin list view.

    - list_display – A list of fields to be displayed in the admin list view.

    - extra_list_display – A list of extra/optional fields to be displayed in the admin list view.

    - list_filter – A list of fields to be used as filters in the admin list view.

    - extra_list_filter – A list of extra/optional fields to be used as filters in the admin list view.

## Implementations

class building_blocks.admin.blocks.base.HasUUIDAdminBlock

  Bases: `AdminBlock`

  AdminBlock for models extending building_blocks.models.blocks.HasUUID

  Parameters

    - readonly_fields – (UUID,)

    - admin_fields – (UUID,)

class building_blocks.admin.blocks.base.HasSlugAdminBlock

  Bases: `AdminBlock`

  AdminBlock for models with a slug field

  Parameters

    - admin_fields – (SLUG,)

    - edit_readonly_fields – (SLUG,)

class building_blocks.admin.blocks.base.TimeStampedAdminBlock

  Bases: `AdminBlock`

  AdminBlock for models extending TimeStampedModel

  Parameters

    - readonly_fields – (CREATED, MODIFIED)

    - admin_fields – (CREATED,)

    - extra_admin_fields – (MODIFIED,)

class building_blocks.admin.blocks.UnnamedBaseKaosModelAdminBlock

  AdminBlock for models extending UnnamedBaseKaosModel

  Parameters

    - admin_fields – (UUID, CREATED)

    - extra_admin_fields – (MODIFIED,)

    - readonly_fields – (UUID, CREATED, MODIFIED,)

class building_blocks.admin.blocks.extra.KaosModelAdminBlock

  Bases: `XXXAdminBlock`

  AdminBlock for models extending KaosModel

  Parameters

    - admin_fields – (UUID, CREATED)

    - base_fields – (NAME,)

    - extra_admin_fields – (MODIFIED,)

    - readonly_fields – (UUID, CREATED, MODIFIED,)

    - the_fieldset – (None, {‘fields’: (NAME,)})

class building_blocks.admin.blocks.SluggedKaosModelAdminBlock

  AdminBlock for models extending both SluggedModel and UnnamedBaseKaosModel

  Parameters

    - admin_fields – (SLUG, UUID, CREATED)

    - base_fields – (NAME,)

    - edit_readonly_fields – (SLUG,)

    - extra_admin_fields – (MODIFIED,)

    - readonly_fields – (UUID, CREATED, MODIFIED,)

    - the_fieldset – (None, {‘fields’: (NAME,)})

## Utils

class building_blocks.admin.blocks.base.AdminFieldsetTitle

  Class to hold constant values for django fieldset titles

  Parameters

    - admin – “Admin”

    - extra – “Extra”