Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Interface for querying & updating resource models by node & nodegroup aliases #11595

Open
jacobtylerwalls opened this issue Oct 31, 2024 · 0 comments · May be fixed by #11596
Open

Interface for querying & updating resource models by node & nodegroup aliases #11595

jacobtylerwalls opened this issue Oct 31, 2024 · 0 comments · May be fixed by #11596
Assignees

Comments

@jacobtylerwalls
Copy link
Member

User story

As an arches application developer, I would like to be able to query and update data for a resource model by a semantic label like a node alias (guaranteed unique) or widget label rather than constructing tiles directly and having to know their UUIDs.

Precedents

Proposal

Another approach would be to provide, in core arches, a solution that:

  • annotates resource instance tile data onto the ResourceInstance model instances via Django querysets for Django-native querying, updating, related-object selecting, prefetching, paginating, signalling, etc.
  • dogfoods the existing python application methods (thereby reducing drift) for:
    • tile validation
    • edit log, indexing side effects
    • function triggers
  • generates (customizable) django rest framework serializers from your resource models (similar to the way django rest framework can generate serializers from your django models in general)
  • reads from dynamic graph data, avoiding the need to take snapshots of "well-known" models or write migrations or deploy database views

Demo

Example queries might look like this:

>>> from arches.app.models.models import *
>>> concepts = ResourceInstance.as_model("concept")
Django QuerySet methods are available for efficient queries:
>>> concepts.count()
785
Filter on any nested node at the top level ("shallow query").
In this example, statement_content is a cardinality-N node, thus an array.
# TODO: should name with `_set`? But then would need to check for clashes.
>>> subset = concepts.filter(statement_content__len__gt=0)[:4]
>>> for concept in subset:
print(concept)
for stmt in concept.statement:
print("\t", stmt)
print("\t\t", stmt.statement_content)
<Concept: consignment (method of acquisition) (f3fed7aa-eae6-41f6-aa0f-b889d84c0552)>
<TileModel: statement (46efcd06-a5e5-43be-8847-d7cd94cbc9cb)>
[{'en': {'value': 'Method of acquiring property ...
...
Access child and parent tiles by nodegroup aliases:
>>> has_child = concepts.filter(statement_data_assignment_statement_content__len__gt=0).first()
>>> has_child
<Concept: <appellative_status_ascribed_name_content> (751614c0-de7a-47d7-8e87-a4d18c7337ff)>
>>> has_child.statement_data_assignment_statement
<statement_data_assignment_statement (51e1f473-712e-447b-858e-cc7353a084a6)>
>>> parent = has_child.statement[0]
>>> parent.statement_data_assignment_statement[0].statement is parent
True

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: 🏗 In Progress
Development

Successfully merging a pull request may close this issue.

1 participant