Measurement model#
This page lists the fields, vocabularies, methods, querysets and rules of the Measurement base model that every measurement 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 measurement type. Methods are listed by name only. Their signatures are on the Python API page.
from fairdm.core.measurement.models import Measurement
Measurement is a polymorphic base. A measurement 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. Validating a bare Measurement raises a ValidationError, and MeasurementForm refuses to create one.
Fields#
A measurement 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 measurement belongs to. It may differ from the sample’s dataset. Related name |
A dataset. Required. |
|
|
None |
The sample the measurement was made on. Deleting a sample that still has measurements is refused, unless they are deleted in the same operation. |
A sample of any type. Required. |
|
|
|
The creator’s own identifier for the measurement within its dataset. |
Text. Optional. |
|
|
|
Where the measurement was made, when that differs from where its sample was taken. |
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 measurement’s credits. |
The location fields are described on Location fields. A measurement with no location of its own takes its sample’s, for a viewer who may open the sample. See ADR 0033.
The value fields#
Measurement declares no value or uncertainty field. A type that records a result declares them, and get_value() and print_value() read them.
Field |
Declared by |
Used for |
|---|---|---|
|
The measurement type |
The result. A quantity field, or a plain number. |
|
The measurement type |
The uncertainty of |
The rules are described in How a measurement reports its value.
Names a type cannot reuse#
A field on a measurement 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,sample,local_id,location,location_elevation,location_uncertainty,contributors.Reverse accessors:
descriptions,dates,identifiers.
Class attributes#
Name |
Value |
|---|---|
|
The address of the measurement collection of the contributor roles. |
|
The address of the measurement collection of the date types. |
|
The address of the measurement collection of the description types. |
|
|
Descriptions, dates and identifiers#
MeasurementDescription, MeasurementDate and MeasurementIdentifier link to a measurement by related and are reached as descriptions, dates and identifiers. A measurement has at most one row of each type. type is a ConceptField limited to the measurement collection of its vocabulary, and holds the concept’s address. Saving a row with a type outside the collection raises a ValidationError, even through objects.create(). The types, by identifier:
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. |
The roles a person or organization can hold on a measurement, by identifier, are measurement-preparation, measurement-collection and support.
Methods#
Name |
Returns |
|---|---|
|
The |
|
The result of |
|
The value as text when there is one, otherwise the |
|
An |
|
The address of the measurement’s overview page. |
|
The card templates to try, |
clean() refuses to move a measurement to a dataset when that would leave nobody able to manage it.
EffectiveLocation#
EffectiveLocation is a named tuple that effective_location_for() returns.
Attribute |
Type |
What it holds |
|---|---|---|
|
|
The location. |
|
|
Metres above mean sea level. |
|
|
Metres. |
|
|
|
Queryset#
Measurement.objects serves MeasurementQuerySet, which is polymorphic. Every method returns a queryset and chains with the others. A type’s own queryset should extend it, as in How to add queryset methods to a measurement type.
Method |
Returns |
|---|---|
|
The measurements with sample, dataset, credits and their roles loaded. |
|
The measurements with descriptions, dates and identifiers loaded. |
|
The measurements with |
|
The measurements whose effective location lies in a polygon or a |
|
The measurements whose effective location is within a distance of a point. |
|
The measurements ordered by distance of their effective location, each carrying |
|
The measurements whose own dataset is published. |
|
The measurements the user may see. |
|
The measurements on which the user holds at least a level. |
|
The measurements the user may act on at a level. |
|
Measurements that are, or are not, of the given types. These come from django-polymorphic. |
A measurement follows its own dataset for access, not its sample’s. The visibility and level methods are described on Contribution levels and record access.
Meta#
Option |
Value |
|---|---|
|
|
|
|
|
|
Base configuration#
BaseMeasurementConfiguration in fairdm.core.measurement.config is the registry configuration to extend for a measurement type.
Attribute |
Value |
|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
For the form, table and filter set, the component’s own list above comes first and the type’s fields follow, minus anything in exclude. The serializer, resource and admin read only the type’s fields, so a type lists name, sample and dataset there too. Because the base sets form_fields, table_fields and filterset_fields, a type that supplies form_class, table_class or filterset_class sets the matching field list to None. See Model configuration.
Admin, form and filter bases#
Class |
Module |
Described on |
|---|---|---|
|
|
|
|
|
|
|
|