"""
Modèles du schéma gn_commons
"""
from sqlalchemy.dialects.postgresql import JSONB
from utils_flask_sqla.serializers import serializable
from geonature.utils.env import DB
from .base import cor_field_module, cor_field_object, cor_field_dataset
from geonature.core.gn_meta.models import TDatasets
from geonature.core.gn_permissions.models import PermObject
@serializable
[docs]
class TAdditionalFields(DB.Model):
[docs]
__tablename__ = "t_additional_fields"
[docs]
__table_args__ = {"schema": "gn_commons"}
[docs]
id_field = DB.Column(DB.Integer, primary_key=True)
[docs]
field_name = DB.Column(DB.String, nullable=False)
[docs]
field_label = DB.Column(DB.String, nullable=False)
[docs]
required = DB.Column(DB.Boolean)
[docs]
description = DB.Column(DB.String)
[docs]
quantitative = DB.Column(DB.Boolean, default=False)
[docs]
unity = DB.Column(DB.String(50))
[docs]
field_values = DB.Column(JSONB)
[docs]
code_nomenclature_type = DB.Column(
DB.String,
DB.ForeignKey("ref_nomenclatures.bib_nomenclatures_types.mnemonique"),
)
[docs]
additional_attributes = DB.Column(JSONB)
[docs]
id_list = DB.Column(DB.Integer)
[docs]
exportable = DB.Column(DB.Boolean, default=True)
[docs]
field_order = DB.Column(DB.Integer)
[docs]
bib_nomenclature_type = DB.relationship("BibNomenclaturesTypes")
additional_attributes = DB.Column(JSONB)
[docs]
multiselect = DB.Column(DB.Boolean)
[docs]
api = DB.Column(DB.String)
[docs]
default_value = DB.Column(DB.String)
[docs]
modules = DB.relationship(
"TModules",
secondary=cor_field_module,
)
[docs]
objects = DB.relationship(PermObject, secondary=cor_field_object)
[docs]
datasets = DB.relationship(
TDatasets, secondary=cor_field_dataset, back_populates="additional_fields"
)
[docs]
def __str__(self):
return f"{self.field_label} ({self.description})"