Cheatsheet¶
All of the examples below use device = ExperimentalDevice.objects.first() from example_project/laboratory/models.py as the base object. The ExperimentalDevice model has a portal_diameter field that is a DecimalPintField with a default unit of meter and unit choices of meter, centimeter, and foot.
The exact magnitudes shown here come from the bundled example data and can vary if you repopulate the demo database. The access patterns, return types, and formatting behavior are the important parts to rely on.
Access and Conversion Examples¶
Basic Field Access¶
Description |
Code |
Output |
|---|---|---|
Field type |
|
|
Direct string output |
|
|
Magnitude |
|
|
Units |
|
|
Quantity type |
|
|
Quantity value |
|
|
Quantity magnitude |
|
|
Quantity units |
|
|
get_FOO_display() method |
|
|
get_FOO_display() with digits |
|
|
get_FOO_display() with format_string |
|
|
get_FOO_display() with digits and format_string |
|
|
Unit Conversions¶
Description |
Code |
Output |
|---|---|---|
Convert to kilometers (proxy) |
|
|
Convert to centimeters (proxy) |
|
|
Convert to millimeters (proxy) |
|
|
Convert to kilometers (quantity) |
|
|
Convert to centimeters (quantity) |
|
|
Convert to millimeters (quantity) |
|
|
Decimal Formatting¶
Description |
Code |
Output |
|---|---|---|
Format with 2 decimal places |
|
|
Format with 3 decimal places |
|
|
Format with 4 decimal places |
|
|
Convert to km with 3 decimal places |
|
|
Convert to cm with 2 decimal places |
|
|
Convert to mm with 1 decimal place |
|
|
Aggregations¶
Description |
Code |
Output |
|---|---|---|
count |
|
|
avg_diameter base value |
|
|
avg_diameter raw Quantity |
|
|
avg_diameter raw Quantity magnitude |
|
|
avg_diameter raw Quantity converted to km |
|
|
avg_diameter in centimeters |
|
|
avg_diameter formatted (2 places) |
|
|
max_diameter base value |
|
|
max_diameter raw Quantity |
|
|
max_diameter raw Quantity magnitude |
|
|
max_diameter raw Quantity converted to km |
|
|
max_diameter in centimeters |
|
|
max_diameter formatted (2 places) |
|
|
std_dev_diameter base value |
|
|
std_dev_diameter raw Quantity |
|
|
std_dev_diameter raw Quantity magnitude |
|
|
std_dev_diameter raw Quantity converted to km |
|
|
std_dev_diameter in centimeters |
|
|
std_dev_diameter formatted (2 places) |
|
|
Advanced Features¶
Description |
Code |
Output |
|---|---|---|
Original value |
|
|
To km with 3 decimal places |
|
|
To cm with 2 decimal places |
|
|
Kilometer conversion magnitude |
|
|
Kilometer conversion units |
|
|
Comparison Operations¶
Description |
Code |
Output |
|---|---|---|
First device diameter |
|
|
Second device diameter |
|
|
Equal comparison |
|
|
Greater than comparison |
|
|
Less than comparison |
|
|
Field Metadata¶
Description |
Code |
Output |
|---|---|---|
Default unit |
|
|
Unit choices |
|
|
Display decimal places |
|
|
Template Examples¶
Basic Field Access¶
Description |
Template Code |
Output |
|---|---|---|
Direct output |
|
|
Magnitude only |
|
|
Units only |
|
|
Raw Pint Quantity object |
|
|
Raw Pint Quantity object (magnitude) |
|
|
Raw Pint Quantity object (units) |
|
|
Decimal Place Formatting¶
Description |
Template Code |
Output |
|---|---|---|
0 decimal places |
|
|
2 decimal places |
|
|
5 decimal places |
|
|
5 decimal places, magnitude only |
|
|
Direct Conversions¶
Description |
Template Code |
Output |
|---|---|---|
Direct conversion (meter) |
|
|
Direct conversion (centimeter) |
|
|
Direct conversion (foot) |
|
|
Direct conversion (foot) magnitude only |
|
|
Direct conversion (foot) units only |
|
|
Direct conversion (foot) with 0 decimal places |
|
|
Direct conversion (foot) with 2 decimal places |
|
|
Direct conversion (foot) with 5 decimal places |
|
|
Template Filters¶
Description |
Template Code |
Output |
|---|---|---|
Magnitude only |
|
|
Magnitude only with 2 decimal places |
|
|
Units only |
|
|
Convert to meter |
|
|
Convert to meter with 2 decimals |
|
|
Convert to meter, magnitude only |
|
|
Convert to meter, magnitude only |
|
|
Convert to meter, units only |
|
|
Convert to centimeter |
|
|
Convert to centimeter with 2 decimals |
|
|
Convert to centimeter, magnitude only |
|
|
Convert to centimeter, magnitude only |
|
|
Convert to centimeter, units only |
|
|
Convert to foot |
|
|
Convert to foot with 2 decimals |
|
|
Convert to foot, magnitude only |
|
|
Convert to foot, magnitude only |
|
|
Convert to foot, units only |
|
|
Format String Examples¶
Description |
Template Code |
Output |
|---|---|---|
Default format |
|
|
Default format (explicitly stated) |
|
|
Compact format |
|
|
Scientific notation |
|
|
Fixed point (2 places) |
|
|
Compact fixed point (2 places) |
|
|
Fixed point (2 places), units only |
|
|
Combined Operations¶
Description |
Template Code |
Output |
|---|---|---|
Convert, format & style |
|
|
Convert, format & style |
|
|
Convert, format & style |
|
|
Comparisons¶
Description |
Template Code |
Output |
|---|---|---|
Equal to other device |
|
|
Equal to other device |
|
|
Greater than other device |
|
|
Less than other device |
|
|
Aggregation Examples¶
Portal_Diameter_Avg¶
Description |
Template Code |
Output |
|---|---|---|
Base value |
|
|
With 2 decimals |
|
|
In base units |
|
|
In meter |
|
|
In centimeter |
|
|
In foot |
|
|
Portal_Diameter_Max¶
Description |
Template Code |
Output |
|---|---|---|
Base value |
|
|
With 2 decimals |
|
|
In base units |
|
|
In meter |
|
|
In centimeter |
|
|
In foot |
|
|
Portal_Diameter_Min¶
Description |
Template Code |
Output |
|---|---|---|
Base value |
|
|
With 2 decimals |
|
|
In base units |
|
|
In meter |
|
|
In centimeter |
|
|
In foot |
|
|
Portal_Diameter_Sum¶
Description |
Template Code |
Output |
|---|---|---|
Base value |
|
|
With 2 decimals |
|
|
In base units |
|
|
In meter |
|
|
In centimeter |
|
|
In foot |
|
|