Models

Models

class building_blocks.models.KaosModel(*args, **kwargs)

Bases: BaseKaosModel, RulesModel

Abstract Base Model that comes with UUID, create and modified, and name fields. Powered up by django-rules through RulesModel.

class building_blocks.models.UnnamedKaosModel(*args, **kwargs)

Bases: UnnamedBaseKaosModel, RulesModel

Abstract Base Model that comes with UUID, create and modified fields. Powered up by django-rules through RulesModel. Cousin of KaosModel but without the name field.

class building_blocks.models.SluggedKaosModel(*args, **kwargs)

Bases: SluggedModel, KaosModel

KaosModel with slug.

Mixins

class building_blocks.models.HasUUIDModel(*args, **kwargs)

Bases: Model

Add a unique UUID field to the model

class building_blocks.models.NamedModel(*args, **kwargs)

Bases: Model

Model with a name field. __str__() reflects the name.

class building_blocks.models.SluggedModel(*args, **kwargs)

Bases: HasAutoFields, Model

Model with a slug field. Optionally autogenerate from another field denoted by slug_source

class building_blocks.models.OrderableModel(*args, **kwargs)

Bases: Model

Adds field order to the inheriting model. Used for manual sorting.

class building_blocks.models.Orderable0Model(*args, **kwargs)

Bases: OrderableModel

Same as OrderableModel, but the default order is set to 0 instead of a large number.

Base

class building_blocks.models.UnnamedBaseKaosModel(*args, **kwargs)

Bases: HasUUIDModel, TimeStampedModel, Model

class building_blocks.models.BaseKaosModel(*args, **kwargs)

Bases: NamedModel, UnnamedBaseKaosModel

Abstracts

class building_blocks.models.Archivable(*args, **kwargs)

Bases: ArchivableInterface, Model

Provides and interface to create archivable (or soft deletable) models. If you don’t want to delete an instance from your DB, but want to mark it inactive use this abstract model. Filter for available (i.e. not archived) objects using the queryset method .available(). It is provided through the model’s objects manager.

archive(force=False)

Set the object as archived.

Parameters

force – By default, the method checks if the object is archived and will through an error if it is. Set force to True to disable this check.

restore(force=False)

Set the object as not archived (available).

Parameters

force – By default, the method checks if the object is not archived and will through an error if it is. Set force to True to disable this check.

class building_blocks.models.StatusArchivable(*args, **kwargs)

Bases: ArchivableInterface, HasStatus, Model

archive()

Set the object as archived.

restore()

Set the object as not archived (available).

class building_blocks.models.Publishable(*args, **kwargs)

Bases: StatusArchivable, Model

archive()

Set the object as archived.

restore()

Set the object as not archived (available).

QuerySets

class building_blocks.models.ArchivableQuerySet(model=None, query=None, using=None, hints=None)

Bases: ArchivableQuerySetInterface, QuerySet

archived()
Returns

queryset with db rows that are archived

available()
Returns

queryset with db rows that are “available” (aka not archived)

set_archived()

Archive the objects in this queryset.

Returns

the return value from .update() i.e. the count of rows updated.

set_restored()

Restore (unarchive) the objects in this queryset.

Returns

the return value from .update() i.e. the count of rows updated.

class building_blocks.models.StatusArchivableQuerySet(model=None, query=None, using=None, hints=None)

Bases: ArchivableQuerySetInterface, QuerySet

archived()
Returns

queryset with db rows that are archived

available()
Returns

queryset with db rows that are “available” (aka not archived)

set_archived()

Archive the objects in this queryset.

Returns

the return value from .update() i.e. the count of rows updated.

set_restored()

Restore (unarchive) the objects in this queryset.

Returns

the return value from .update() i.e. the count of rows updated.

class building_blocks.models.PublishableQuerySet(model=None, query=None, using=None, hints=None)

Bases: StatusArchivableQuerySet, QuerySet

archived()
Returns

queryset with db rows that are archived

available()
Returns

queryset with db rows that are “available” (aka not archived)

draft()
Returns

queryset with db rows that are in draft

published()
Returns

queryset with db rows that are published

set_archived()

Archive the objects in this queryset.

Returns

the return value from .update() i.e. the count of rows updated.

set_published()

Publish the objects in this queryset.

Returns

the return value from .update() i.e. the count of rows updated.

set_restored()

Restore (unarchive) the objects in this queryset.

Returns

the return value from .update() i.e. the count of rows updated.

set_unpublished()

Unpublish the objects (set to draft) in this queryset.

Returns

the return value from .update() i.e. the count of rows updated.

Interfaces

class building_blocks.models.interfaces.ArchivableInterface

Interface for Archivable objects

archive(*args, **kwargs)

Set the object as archived.

restore(*args, **kwargs)

Set the object as not archived (available).

unarchive(*args, **kwargs)

Set the object as not archived (available).

class building_blocks.models.interfaces.ArchivableQuerySetInterface(model=None, query=None, using=None, hints=None)

Default queryset interface for Archivable objects. Adds queryset methods to interact with the Archivable interface.

archived()
Returns

queryset with db rows that are archived

available()
Returns

queryset with db rows that are “available” (aka not archived)

set_archived()

Archive the objects in this queryset.

Returns

the return value from .update() i.e. the count of rows updated.

set_restored()

Restore (unarchive) the objects in this queryset.

Returns

the return value from .update() i.e. the count of rows updated.

Blocks

class building_blocks.models.blocks.HasUUIDModel(*args, **kwargs)

Add a unique UUID field to the model

class building_blocks.models.blocks.NamedModel(*args, **kwargs)

Model with a name field. __str__() reflects the name.

class building_blocks.models.blocks.Orderable0Model(*args, **kwargs)

Same as OrderableModel, but the default order is set to 0 instead of a large number.

class building_blocks.models.blocks.OrderableModel(*args, **kwargs)

Adds field order to the inheriting model. Used for manual sorting.

class building_blocks.models.blocks.SluggedModel(*args, **kwargs)

Model with a slug field. Optionally autogenerate from another field denoted by slug_source

set_auto_fields()

Override this method to set the fields that need to be automatically set

class building_blocks.models.blocks.TitledModel(*args, **kwargs)

Model with a title field. __str__() reflects the title.