Skip to main content

Additional, dynamic fields for all Django models.

Project description

https://travis-ci.org/matthiask/django-specifications.png?branch=master

This module offers an easy way to attach auxiliary information to Django models. It allows configuring custom forms through the administration interface.

Usage

  1. Add "specifications" to INSTALLED_APPS.

  2. Create a specification = ForeignKey("specifications.Specification") on the model you want to use specifications with. The foreign key can be nullable or required, as you wish.

  3. Create the place where the specification field data is actually stored:

    from specifications.models import SpecificationValueFieldBase
    
    class MyObjectField(SpecificationValueFieldBase):
        parent = models.ForeignKey(
            MyObject,
            on_delete=models.CASCADE,
            related_name="fields",
        )
    
        class Meta:
            ordering = ["field__group__ordering", "ordering"]
  4. Inherit from FormWithSpecification when creating your ModelForm:

    from specifications.forms import FormWithSpecification
    
    class MyObjectForm(FormWithSpecification):
        class Meta:
            model = MyObject
  5. If you want to edit models with specifications you might want to use the following snippet:

    from specifications.admin import ModelAdminWithSpecification
    
    class MyObjectAdmin(ModelAdminWithSpecification):
        def get_fieldsets(self, request, obj=None):
            # Define your fieldsets
            fieldsets = [...]
            if self.can_add_specification_fields(request, obj):
                # Extend your fieldset with specification fields
                fieldsets.extend(...)
            return fieldsets

The fields are available after saving a specification. The specification can be changed, but you risk losing data if you do this.

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-specifications-0.4.0.tar.gz (10.4 kB view details)

Uploaded Source

Built Distribution

django_specifications-0.4.0-py2.py3-none-any.whl (14.0 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file django-specifications-0.4.0.tar.gz.

File metadata

  • Download URL: django-specifications-0.4.0.tar.gz
  • Upload date:
  • Size: 10.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.6.8

File hashes

Hashes for django-specifications-0.4.0.tar.gz
Algorithm Hash digest
SHA256 06b7987be8af6e1ba2991d30d0a6d6ab8dc9a0f3b0849c89f6216870992f07b6
MD5 4ad66aef782a3b31b70466660ea7eecf
BLAKE2b-256 1c1f1bed6a0585878962f0164034da245fdcf4ae68a3c287337b7c1e515b359a

See more details on using hashes here.

File details

Details for the file django_specifications-0.4.0-py2.py3-none-any.whl.

File metadata

  • Download URL: django_specifications-0.4.0-py2.py3-none-any.whl
  • Upload date:
  • Size: 14.0 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.6.8

File hashes

Hashes for django_specifications-0.4.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 bd660ad78102b71ff9db4385ad7c11d5f56867b0f294e4498f74e621447b66c4
MD5 e87138a75e89209ac221939b16264cd0
BLAKE2b-256 83a61f935d37c85349ad20aba6e4fc8dd5ba4f580024fb0b93f57f96145fa568

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