Update add_linked: add relationship fields manually

This commit is contained in:
PCoder 2021-07-28 17:02:58 +05:30
parent 5253d00c3e
commit 0c285ca072

View file

@ -24,7 +24,8 @@ def fix_url(link):
# Create linked objects
def add_linked(person, field, obj, data):
def add_linked(person, obj, data):
field = []
# TODO: fuzzy matching instead of lower()
items = fix_bracketed_lists(data).lower()
items = items.replace(';', ',').split(',')
@ -38,6 +39,7 @@ def add_linked(person, field, obj, data):
tgt.name = n
tgt.save()
field.append(tgt)
return field
# Fetch an object by source_id (numeric identifier used in source DB)
@ -116,10 +118,14 @@ def refresh_data(filename, fmt=None):
person.personal_url = fix_url(row['URL'])
with transaction.atomic():
add_linked(person, person.research_methods, Method, row['Methods'])
add_linked(person, person.research_scales, Scale, row['Scale'])
add_linked(person, person.research_taxa, Taxon, row['Taxa'])
add_linked(person, person.research_fields, Field, row['Field of expertise'])
research_methods = add_linked(person, Method, row['Methods'])
person.research_methods = research_methods
research_scales = add_linked(person, Scale, row['Scale'])
person.research_scales = research_scales
research_taxa = add_linked(person, Taxon, row['Taxa'])
person.research_taxa = research_taxa
research_fields = add_linked(person, Field, row['Field of expertise'])
person.research_fields = research_fields
person.index()
person.save()
@ -150,6 +156,7 @@ def refresh_data(filename, fmt=None):
ppl, source_id = get_by_id(row['Person'], Person, first=False)
if not ppl or not ppl.first(): continue
for person in ppl:
person.resources = []
for r in rzs:
person.resources.append(r)
person.save()
@ -162,6 +169,7 @@ def refresh_data(filename, fmt=None):
ppl, source_id = get_by_id(row['Person'], Person, first=False)
if not ppl or not ppl.first(): continue
for person in ppl:
person.ranges = []
for r in rzs:
person.ranges.append(r)
person.save()