Sample model#
This page lists the fields, vocabularies, relations, querysets and rules of the Sample base model that every sample type extends. It does not list the fields all four core records share, which are on Core models, or show how to write a type, which is in How to add a sample type. Methods are listed by name only. Their signatures are on the Python API page.
from fairdm.core.sample.models import Sample
Sample is a polymorphic base. A sample type is a subclass that adds its own fields, and each type has a table of its own. See How sample and measurement types are stored. The base model cannot be saved. Saving a bare Sample by any route raises a ValidationError, and full_clean() on one reports the same error.
Fields#
A sample has the fields of every core record and these.
Field |
Type |
Default |
What it does |
Accepts |
|---|---|---|---|---|
|
|
Generated, prefix |
The identifier used in addresses and the API. |
Not editable. Unique. |
|
|
None |
The dataset the sample first appeared in. Related name |
A dataset. Required. |
|
|
|
The creator’s own identifier for the sample within its dataset. It need not be unique. |
Text. Optional. |
|
|
The address of |
The custody state of the physical specimen. |
The address of a status. |
|
|
|
Where the sample was taken, as a point in WGS 84. |
A point. Optional. |
|
|
|
Metres above mean sea level. Negative below it. |
A number. Needs a location. |
|
|
|
The distance in metres from the location within which the true place lies. |
A number of zero or more. Needs a location. |
|
|
The sample’s credits. |
||
|
|
Empty |
The samples this one is related to. Not symmetrical. Related name |
Samples. Optional. |
Two check constraints keep the location fields consistent: an uncertainty is empty or zero or more, and an elevation or uncertainty needs a location. The location fields are described on Location fields. The reasoning for keeping a location on each record is in ADR 0032.
Names a type cannot reuse#
A field on a sample type that has one of these names clashes with an inherited field or a reverse accessor.
Fields:
id,polymorphic_ctype,added,modified,image,name,keywords,tags,options,dataset,uuid,local_id,status,location,location_elevation,location_uncertainty,contributors,related.Reverse accessors:
descriptions,dates,identifiers,measurements,related_samples,related_to,related_from.
Status#
Sample.status holds the address of one of the concepts of the sample status vocabulary, https://w3id.org/fairdm/vocabularies/sample-status, which fairdm.core.vocabularies names SAMPLE_STATUS. A concept’s address is the vocabulary’s address, a slash and the identifier below. A sample can move from any status to any other, including out of destroyed.
Identifier |
Label |
Meaning |
|---|---|---|
|
Available |
Accessible and not checked out, in storage or destroyed. |
|
In Use |
Checked out or in active use. |
|
Stored |
In long-term storage. |
|
Destroyed |
Consumed, destroyed or otherwise no longer physically available. |
|
Unknown |
The custody state is not known. |
Class attributes#
Name |
Value |
|---|---|
|
The address of the sample collection of the contributor roles. |
|
The address of the sample collection of the date types. |
|
The address of the sample collection of the description types. |
|
|
Descriptions, dates and identifiers#
SampleDescription, SampleDate and SampleIdentifier link to a sample by related and are reached as descriptions, dates and identifiers. A sample has at most one row of each type. type is a ConceptField limited to the sample collection of its vocabulary, and holds the concept’s address. full_clean() refuses a type outside the collection, but a plain objects.create() does not call it. The types, by identifier, in the order their collections list them:
Rows |
Types |
|
|---|---|---|
|
|
Text of at most 20,000 characters. |
|
|
A partial date. See Model fields. |
|
|
Text of at most 255 characters, unique across every kind of record. |
When an identifier is validated, a common display prefix is removed first: https://doi.org/, http://doi.org/, https://igsn.org/, hdl.handle.net/, doi: or igsn:. An IGSN must then be a DataCite DOI (10. followed by four to nine digits, a slash and a suffix) or a legacy handle beginning 10273/. The match ignores case.
The roles a person or organization can hold on a sample, by identifier, are collection, preparation, storage, destruction and restoration.
SampleRelation#
SampleRelation records that one sample came from another. It has no timestamps.
Field |
Type |
Default |
What it does |
Accepts |
|---|---|---|---|---|
|
|
None |
The kind of relationship. |
|
|
|
None |
The child. Related name |
A sample. |
|
|
None |
The parent. Related name |
A sample. |
The combination of source, target and type is unique. Both clean() and save() refuse a sample related to itself and a link whose reverse already exists with the same type. For the steps, see How to record sample relationships.
Methods#
Name |
Returns |
|---|---|
|
The |
|
The samples related to this one in either direction, optionally of one type. |
|
The samples that are children of this one. |
|
The samples that are parents of this one. |
|
The descendants, to a depth. |
|
The ancestors, to a depth. |
|
The address of the sample’s overview page. |
|
The card templates to try, |
clean() also refuses to move a sample to a dataset when that would leave nobody able to manage it.
Queryset#
Sample.objects serves SampleQuerySet, which is polymorphic. Every method returns a queryset and chains with the others.
Method |
Returns |
|---|---|
|
The samples with dataset, project and credits loaded. |
|
The samples with descriptions, dates and identifiers loaded. |
|
The samples with keywords loaded. |
|
With |
|
The descendants of a sample. |
|
The ancestors of a sample. |
|
The samples located in a polygon or a |
|
The samples within a distance of a point, measured on the ground. |
|
The samples ordered by distance, each carrying |
|
The samples whose own dataset is published. |
|
The samples the user may see. |
|
The samples on which the user holds at least a level. |
|
The samples the user may act on at a level. |
|
Samples that are, or are not, of the given types. These come from django-polymorphic. |
inside, within_distance and nearest are described on Location fields. The visibility and level methods are described on Contribution levels and record access.
Meta#
Option |
Value |
|---|---|
|
|
|
|
|
|
Base configuration#
BaseSampleConfiguration in fairdm.core.sample.config is the registry configuration to extend for a sample type. It sets only fields.
Attribute |
Value |
|---|---|
|
|
It sets no per-component field list, so a subclass that sets fields changes every component at once. See Model configuration.