schematools.contrib.django.models module

The Django models for Amsterdam Schema data.

When models are generated with model_factory(), they all inherit from DynamicModel to have a common interface.

When the schema data is imported, the models Dataset, DatasetTable, DatasetField and Profile are all filled.

Generated Models

class schematools.contrib.django.models.DynamicModel(*args, **kwargs)

Base class to tag and detect dynamically generated models.

CREATION_COUNTER = None

Overwritten by subclasses / factory

classmethod get_dataset() Dataset

Give access to the original dataset that this models is part of.

classmethod get_dataset_id() str

Give access to the original dataset ID that this model is part of.

classmethod get_dataset_path() str

Give access to the api path this dataset should be published on.

classmethod get_dataset_schema() DatasetSchema

Give access to the original dataset schema that this model is a part of.

classmethod get_display_field() str | None

Return the name of the display field, for usage by Django models.

classmethod get_field_schema(model_field: models.Field | models.ForeignObjectRel) DatasetFieldSchema

Provide access to the underlying amsterdam schema field that created the model field.

classmethod get_table_id() str

Give access to the table name

classmethod has_display_field() bool

Tell whether a display field is configured.

classmethod has_parent_table() bool

Check if table is sub table for another table.

classmethod is_temporal() bool

Indicates if this model has temporary characteristics.

classmethod table_schema() DatasetTableSchema

Give access to the original table_schema that this model implements.

Metadata Tables

class schematools.contrib.django.models.Dataset(*args, **kwargs)

A registry of all available datasets that are uploaded in the API server.

Each model holds the contents of an “Amsterdam Schema”, that contains multiple tables.

Parameters
  • id (BigAutoField) – Id

  • name (CharField) – Name

  • schema_data (TextField) – Amsterdam schema contents

  • version (CharField) – Schema version

  • is_default_version (BooleanField) – Default version

  • enable_api (BooleanField) – Enable api

  • enable_db (BooleanField) – Enable db

  • endpoint_url (URLField) – Endpoint url

  • path (TextField) – Path

  • auth (CharField) – Authorization

  • ordering (IntegerField) – Ordering

classmethod create_for_schema(schema: DatasetSchema, path: str | None = None) Dataset

Create the schema based on the Amsterdam Schema JSON input

create_models(base_app_name: str | None = None, base_model: type[M] = <class 'schematools.contrib.django.models.DynamicModel'>) list[type[M]]

Extract the models found in the schema

save_for_schema(schema: DatasetSchema)

Update this model with schema data

schema

Provide access to the schema data.

class schematools.contrib.django.models.DatasetTable(*args, **kwargs)

Exposed metadata per schema.

This table can be read by the ‘geosearch’ project to locate all our tables and data sources.

Parameters
  • id (BigAutoField) – Id

  • dataset (ForeignKey to Dataset) – Dataset

  • name (CharField) – Name

  • version (TextField) – Version

  • auth (CharField) – Auth

  • enable_geosearch (BooleanField) – Enable geosearch

  • db_table (CharField) – Db table

  • display_field (CharField) – Display field

  • geometry_field (CharField) – Geometry field

  • geometry_field_type (CharField) – Geometry field type

  • is_temporal (BooleanField) – Is temporal

class schematools.contrib.django.models.DatasetField(*args, **kwargs)

Exposed metadata per field.

Parameters
  • id (BigAutoField) – Id

  • table (ForeignKey to DatasetTable) – Table

  • name (CharField) – Name

  • auth (CharField) – Auth

class schematools.contrib.django.models.Profile(*args, **kwargs)

User Profile.

Parameters
  • id (BigAutoField) – Id

  • name (CharField) – Name

  • scopes (CharField) – Scopes

  • schema_data (TextField) – Amsterdam schema contents

get_scopes()

The auth scopes for this profile

schema

Provide access to the schema data