-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for metadata references (#25)
* add support for metadata references * add more documentation * use same alias scheme as other models
- Loading branch information
Showing
3 changed files
with
49 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
"""Models for the metadata stored in SLIMS.""" | ||
from pydantic import Field | ||
from typing import Optional | ||
from aind_slims_api.models.base import SlimsBaseModel | ||
|
||
|
||
class SlimsMetadataReference(SlimsBaseModel): | ||
"""Model for an instance of the metadata reference in SLIMS. Metadata | ||
content is added to metadata references in the form of attachments. | ||
Examples | ||
-------- | ||
>>> from aind_slims_api import SlimsClient | ||
>>> from aind_slims_api import models | ||
>>> client = SlimsClient() | ||
### Read | ||
>>> metadata_reference = client.fetch_model( | ||
... models.SlimsMetadataReference, | ||
... name="323_EPHYS1_OPTO_20240212" | ||
... ) | ||
>>> attachments = client.fetch_attachments(metadata_reference) | ||
>>> metadata = client.fetch_attachment_content(attachments[0]) | ||
>>> metadata.json()["rig_id"] | ||
'323_EPHYS1_OPTO_2024-02-12' | ||
### Write | ||
>>> import json | ||
>>> attachment_pk = client.add_attachment_content( | ||
... metadata_reference, | ||
... "test_metadata_attachment_name", | ||
... json.dumps({"rig_id": "323_EPHYS1_OPTO_2024-02-12"}) | ||
... ) | ||
""" | ||
|
||
name: str = Field( | ||
..., | ||
serialization_alias="rdrc_name", | ||
validation_alias="rdrc_name", | ||
) | ||
pk: Optional[int] = Field( | ||
None, | ||
serialization_alias="rdrc_pk", | ||
validation_alias="rdrc_pk", | ||
) | ||
_slims_table = "ReferenceDataRecord" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,7 @@ | |
"ContentEvent", | ||
"Unit", | ||
"Result", | ||
"ReferenceDataRecord", | ||
"Test", | ||
"User", | ||
"Groups", | ||
|