Create a custom field type
See the built-in reference for the definition fields and available built-ins.
Register a field for warehouse codes
Create a distinct Django field subclass so Bloomerp can resolve the field type by class.
python
from django.db import models
from bloomerp.field_types.registry import FIELD_TYPE_REGISTRY, FieldTypeDefinition
from bloomerp.lookups.builtins import EQUALS
class WarehouseCodeField(models.CharField):
'''Store a warehouse code as short text.'''
warehouse_code = FieldTypeDefinition(
id="ExampleWarehouseCode",
label="Warehouse code",
description="A short warehouse reference.",
model_field_cls=WarehouseCodeField,
lookups=(EQUALS,),
)
FIELD_TYPE_REGISTRY.register("EXAMPLE_WAREHOUSE_CODE", warehouse_code)Expose constructor defaults in the model builder
The model builder can apply the field constructor arguments when it creates the field.
python
from django.db import models
from bloomerp.field_types.registry import FIELD_TYPE_REGISTRY, FieldConstruction, FieldTypeDefinition
class AssetLabelField(models.CharField):
'''Store an asset label as short text.'''
asset_label = FieldTypeDefinition(
id="ExampleAssetLabel",
label="Asset label",
model_field_cls=AssetLabelField,
construction=FieldConstruction(defaults={"max_length": 40}),
)
FIELD_TYPE_REGISTRY.register("EXAMPLE_ASSET_LABEL", asset_label)