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 details)

Uploaded Source

Built Distribution

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

Uploaded Python 3

File details

Details for the file django-building-blocks-0.0.1.tar.gz.

File metadata

  • Download URL: django-building-blocks-0.0.1.tar.gz
  • Upload date:
  • Size: 8.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.6.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.9.5

File hashes

Hashes for django-building-blocks-0.0.1.tar.gz
Algorithm Hash digest
SHA256 7b66961f50ec258c258eb95dab4ade31bf2fc08c32abdf126bbb445c2ccde481
MD5 21eb9d73f8cf47e9a120921d3b6f14e2
BLAKE2b-256 1c00ae18cee9b19c792f3bbbdf9bee9c1cf111de03143f38675bd9f6a65b487e

See more details on using hashes here.

File details

Details for the file django_building_blocks-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: django_building_blocks-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 10.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.6.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.9.5

File hashes

Hashes for django_building_blocks-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 718f6bc2ba262bcb77d59ec6ebde4471b54dcafdfc8edcc108206fc7af02a787
MD5 0b94ae2b8747c4d22f28d14de1564ce5
BLAKE2b-256 87041c4a4dd9a81c04d7a6b61c9fc139ebaa38ed7911f69062307d85e2a074b8

See more details on using hashes here.

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