Contrib — Django Building Blocks documentation

# Contrib

Contents

- Contrib

  - Admin

  - Models

## Admin

class building_blocks.contrib.admin.DuplicableAdminMixin
  change_actions = ('duplicate',)
  duplicate(request, obj)

class building_blocks.contrib.admin.HasGeneratableImageAdminMixin
  actions = ('generate_image',)
  change_actions = ('generate_image',)
  generate_image(request, queryset)
  property media

class building_blocks.contrib.admin.HasImageAdminMixin
  fieldsets = (('Display', {'fields': ('image_display',)}),)
  image_display(obj)
  property media
  readonly_fields = ('image_display',)

class building_blocks.contrib.admin.HasTimeRangeAdmin
  fields = ('_time_range_dynamic', '_time_range_start', '_time_range_end')
  property media
  readonly_fields = ('time_range__start', 'time_range__end')

class building_blocks.contrib.admin.SnapshotableAdminMixin
  change_actions = ('snapshot',)
  snapshot(request, obj)

class building_blocks.contrib.admin.WithLinkDisplayAdminMixin

  Add a link_display admin display method to show a certain url as a link.

  get_link_content(obj)
  get_link_url(obj)
  link_content = '🔗 Link'
  link_display(obj)
  link_field = None
  list_display = ('link_display',)
  readonly_fields = ('link_display',)

class building_blocks.contrib.admin.WithPNGVisualizeAdminMixin
  property media
  visualize_display(obj: HasVisualizationInterface)

class building_blocks.contrib.admin.WithSVGVisualizeAdminMixin
  property media
  visualize_display(obj: HasVisualizationInterface)

class building_blocks.contrib.admin.WithVisualizeAdminMixin
  fieldsets = (('Display', {'fields': ('visualize_display',)}),)
  property media
  readonly_fields = ('visualize_display',)
  visualize_display(obj: HasVisualizationInterface)

## Models

### enums

class building_blocks.contrib.models.enums.DynamicTimeRangeChoice(value)

  Numbers are in seconds, as in seconds ago from now

  last_24hrs = 86400
  last_30days = 2592000
  last_hour = 3600
  last_week = 604800

### fields

class building_blocks.contrib.models.fields.DynamicTimeRangeField(*args, **kwargs)
  deconstruct()

    Return enough information to recreate the field as a 4-tuple:

    > - The name of the field on the model, if contribute_to_class() has been run.

    > - The import path of the field, including the class, e.g. django.db.models.IntegerField. This should be the most portable version, so less specific may be better.

    > - A list of positional arguments.

    > - A dict of keyword arguments.

    Note that the positional or keyword arguments must contain values of the following types (including inner values of collection types):

    > - None, bool, str, int, float, complex, set, frozenset, list, tuple, dict

    > - UUID

    > - datetime.datetime (naive), datetime.date

    > - top-level classes, top-level functions - will be referenced by their full import path

    > - Storage instances - these have their own deconstruct() method

    This is because the values here must be serialized into a text format (possibly new Python code, possibly JSON) and these are the only types with encoding handlers defined.

    There’s no need to return the exact way the field was instantiated this time, just ensure that the resulting field is the same - prefer keyword arguments over positional ones, and omit parameters with their default values.

### interfaces

class building_blocks.contrib.models.interfaces.HasVisualizationInterface
  visualize()

### models

class building_blocks.contrib.models.models.DuplicableModel(*args, **kwargs)
  class Meta
    abstract = False
  duplicate(*args, **kwargs)

class building_blocks.contrib.models.models.HasTimeRangeModel(*args, **kwargs)
  class Meta
    abstract = False
  get__time_range_dynamic_display(*, field=<building_blocks.contrib.models.fields.DynamicTimeRangeField: _time_range_dynamic>)
  property time_range__end
  time_range__start