Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions specifyweb/backend/setup_tool/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
from specifyweb.specify.models import Institution, Discipline
from specifyweb.backend.businessrules.uniqueness_rules import apply_default_uniqueness_rules
from specifyweb.specify.management.commands.run_key_migration_functions import fix_cots, fix_schema_config
from specifyweb.specify.models_utils.model_extras import PALEO_DISCIPLINES, GEOLOGY_DISCIPLINES

import logging
logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -279,6 +280,14 @@ def create_discipline(data, run_apply_schema_defaults_async: bool = True):
'geologictimeperiodtreedef_id': geologictimeperiodtreedef.id
})

paleo_context_child_table = data.get('paleocontextchildtable', None)
if paleo_context_child_table is None:
discipline_type = data.get('type')
if discipline_type in PALEO_DISCIPLINES:
data['paleocontextchildtable'] = 'collectingevent'
elif discipline_type in GEOLOGY_DISCIPLINES:
data['paleocontextchildtable'] = 'collectionobject'

# Assign new Discipline ID
max_id = Discipline.objects.aggregate(Max('id'))['id__max'] or 0
data['id'] = max_id + 1
Expand Down