Skip to main content

Abstract Django base models (and model class factories) to act as building blocks for rapid development of Django database models

Project description

Django Building Blocks

Abstract Django base models (and model class factories) to act as building blocks for rapid development of Django database models

Quick start

pip install django-building-blocks

Classes provided

Check the docstring under each class for their documentation.

Mixin model classes

Abstract model classes

Admin Block classes

Admin blocks aren't meant to be inherited by your model's admin class. Instead, each field in the admin block is used to create your desired admin class. For example:

# example/sample/admin.py

@admin.register(ArchivableHasUUID)
class ArchivableHasUUIDAdmin(
    ArchivableAdmin,  # Inheritable admin to add common functionality. More on this later. 
    admin.ModelAdmin
):
    search_fields = (
        *HasUUIDAdminBlock.search_fields,  # AdminBlock to assist in shaping the admin
    )
    list_display = (
        *HasUUIDAdminBlock.list_display,
        *ArchivableAdminBlock.list_display,
    )
    list_filter = (
        *ArchivableAdminBlock.list_filter,
    )

    readonly_fields = (
        *HasUUIDAdminBlock.readonly_fields,
        *ArchivableAdminBlock.readonly_fields,
    )
    fieldsets = (
        *HasUUIDAdminBlock.fieldsets,
        *ArchivableAdminBlock.fieldsets,
    )

As its name suggests, the model ArchivableHasUUID inherits from both Archivable and HasUUID and thus has fields form both. With admin blocks you can create ArchivableHasUUIDAdmin without mentioning individual fields from each class, adding to the conciseness of your code. It'll also make it hard to miss a field since the AdminBlock has the default and recommended fields for each admin setting.

Available Admin Blocks:

Inheritable Admin classes

Unlike Admin Blocks the following classes are meant to be inherited by your admin class. The usually provide functionality such as common admin actions to your admin.

Please note that the majority of the above classes use django-object-actions to enable admin actions on objects' admin:change pages. To enable this functionality add 'django_object_actions' to your INSTALLED_APPS.

Development and Testing

IDE Setup

Add the example directory to the PYTHONPATH in your IDE to avoid seeing import warnings in the tests modules. If you are using PyCharm, this is already set up.

Running the Tests

Install requirements

pip install -r requirements.txt

For local environment

pytest

For all supported environments

tox

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django-building-blocks-0.0.1.tar.gz (8.8 kB view hashes)

Uploaded Source

Built Distribution

django_building_blocks-0.0.1-py3-none-any.whl (10.5 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page