Skip to main content

Custom fields plugin for model builder

Custom fields

Custom fields allow extending model at configuration time, with the same sources. This plugin adds two types of custom fields - ones defined on an explicit element (usually the "custom_fields" element is used, but any name can be used) and other one inlining the custom fields directly to the main content.

Currently there is no support for inlining custom fields to "metadata" element, but this can be changed in the future.

Model file

Custom fields are defined on the level of "model":

model:
    use: invenio
    custom-fields:
    - element: custom_fields
      config: TEST_CUSTOM_FIELDS
    properties:
        metadata:
            properties:
                title: fulltext

Explicit custom fields

Explicit custom fields are defined using a pair of element name and config variable. In the instance the custom fields will be separated into the element name:

# config

from invenio_records_resources.services.custom_fields.text import KeywordCF

TEST_CUSTOM_FIELDS = [
    KeywordCF('blah')
]
// instance
{
    "metadata": {
        "title": "My Title"
    },
    "custom_fields": {                  // "element" from model
        "blah": "Custom field value"    // as defined in "TEST_CUSTOM_FIELDS" variable
    }
}

Inline custom fields

Inline custom fields are placed on the root level of the instance, without an enclosing element. To define them, just leave the element definition. Note that only 1 definition of inline CF is allowed.

model:
    use: invenio
    custom-fields:
    - config: INLINE_CF
    properties:
        metadata:
            properties:
                title: fulltext
# config

from invenio_records_resources.services.custom_fields.text import KeywordCF

INLINE_CF = [
    KeywordCF('blah')
]
// instance
{
    "metadata": {
        "title": "My Title"
    },
    "blah": "Custom field value"    // as defined in "INLINE_CF" variable
}

Custom fields nested in metadata

Custom fields nested inside the metadata are not supported yet.

Using custom fields

Custom fields influence the jsonschema file (adding a non-checked object or allowing additional properties) and the mapping file (adding an empty mapping for CF).

During deployment time, after the index is created and before data are poured in, a specialized mapping for custom fields must be created. To do so, call

invenio oarepo cf init

Metadata

Release files for oarepo-model-builder-cf 4.0.8

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for oarepo-model-builder-cf 4.0.8
File Size Uploaded
oarepo_model_builder_cf-4.0.8.tar.gz 4.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for oarepo-model-builder-cf 4.0.8
File Interpreter ABI Platform
oarepo_model_builder_cf-4.0.8-py2.py3-none-any.whl Python 2, Python 3 none any Details

Total release size: 13.8 kB

Release files / oarepo_model_builder_cf-4.0.8.tar.gz

Download URL oarepo_model_builder_cf-4.0.8.tar.gz
Size 4.6 kB
Tags Source
SHA-256 checksum
How to use checksums
ca590a70cec738d4546cc75c792068e798ffffa7316e39bc06867397c5359b71
BLAKE2b-256 checksum
How to use checksums
4c88fe05b9d54a15065989cfe3d4a8482a8d0d18a02133c6083d49915082b5fc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.0 CPython/3.12.5

Release files / oarepo_model_builder_cf-4.0.8-py2.py3-none-any.whl

Download URL oarepo_model_builder_cf-4.0.8-py2.py3-none-any.whl
Size 9.2 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
3edc13355ba079fbab1433b3a868dbb009d7f4788c2bbdba39f88f7fdd000d0a
BLAKE2b-256 checksum
How to use checksums
092e3ef0584b6edf3b2e23ea7bc94fb05a27e9e9b4d7eaba6e48a7386c00d669
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.0 CPython/3.12.5

Release history Release notifications | RSS feed

This release

4.0.8 This release

2 release files

4.0.7

2 release files

4.0.6

2 release files

4.0.5

2 release files

4.0.4

2 release files

4.0.3

2 release files

4.0.2

2 release files

4.0.1

2 release files

4.0.0

2 release files

1.0.1

2 release files

1.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page