Django API Reference¶
YoroField (Model Field)¶
yoro.django.fields.YoroField
¶
Bases: CharField
A Django model field that stores a Yoro geographic code.
Behaves like a CharField in the database (stores the code string),
but adds:
- Auto-encoding: assign a
(lat, lon)tuple and it encodes automatically on save. - Validation: rejects invalid codes on form submission.
- Widget: renders an interactive Leaflet map picker in forms.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
domain
|
str
|
ISO country code for the Yoro domain (default |
'CI'
|
precision
|
int
|
Hilbert order — controls resolution (default |
12
|
map_height
|
int
|
Height of the map widget in pixels (default |
300
|
map_attrs
|
dict | None
|
Extra widget configuration ( |
None
|
Example::
class Shop(models.Model):
name = models.CharField(max_length=100)
address = YoroField(domain="CI", precision=12)
# With custom map:
address = YoroField(
domain="CI",
precision=14,
map_height=400,
map_attrs={"tile_url": "https://.../{z}/{x}/{y}.png"},
)
Source code in src/yoro/django/fields.py
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 | |
__init__(*args, domain='CI', precision=12, map_height=300, map_attrs=None, **kwargs)
¶
Source code in src/yoro/django/fields.py
to_python(value)
¶
Accept strings, (lat, lon) tuples, and None.
Source code in src/yoro/django/fields.py
validate(value, model_instance)
¶
Validate that the value is a valid Yoro code.
Source code in src/yoro/django/fields.py
formfield(**kwargs)
¶
Use YoroWidget with the map picker by default.
Source code in src/yoro/django/fields.py
YoroFormField (Form Field)¶
yoro.django.fields.YoroFormField
¶
Bases: CharField
Form field for Yoro codes with validation.
Source code in src/yoro/django/fields.py
YoroWidget (Form Widget)¶
yoro.django.widgets.YoroWidget
¶
Bases: TextInput
A text input with an embedded Leaflet map for Yoro code picking.
The widget renders:
- A monospace text input for the Yoro code
- A Leaflet map (click to encode, auto-decode on input)
- Resolution and coordinate info
All encoding/decoding happens client-side via the JavaScript codec. No server round-trips needed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
domain
|
str
|
ISO country code (default |
'CI'
|
precision
|
int
|
Hilbert order (default |
12
|
map_height
|
int
|
Height of the map in pixels (default |
300
|
tile_url
|
str
|
Tile provider URL template. |
'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png'
|
tile_attribution
|
str
|
Tile attribution text. |
'© OpenStreetMap contributors'
|
Source code in src/yoro/django/widgets.py
Model: GeoAltiusCode¶
yoro.django.models.GeoAltiusCode
¶
Bases: Model
Persisted Yoro geographic address.
Source code in src/yoro/django/models.py
Services¶
Yoro Django services — encode GPS, create/retrieve codes, assign to models.
Usage::
from yoro.django.services import assign_yoro, get_or_create_yoro
# Standalone
obj = get_or_create_yoro(6.8, -5.3, domain="CI")
# On a model instance (modifies in place, does NOT save)
assign_yoro(producer_instance, domain="CI")
assign_yoro(instance, domain='CI', precision=12)
¶
Assign an Altius Code to any model instance with location and yoro fields.
Modifies the instance in place but does not save it.
Source code in src/yoro/django/services.py
get_or_create_yoro(lat, lon, precision=12, domain='CI')
¶
Encode GPS coordinates and get or create a GeoAltiusCode record.
Source code in src/yoro/django/services.py
Views¶
Yoro API views (plain Django — no DRF dependency).
decode_view(request)
¶
Decode an Altius Code to coordinates and cell bounds.
GET /api/v1/yoro/decode/?code=CI-4H7A3B
Source code in src/yoro/django/views.py
domains_view(request)
¶
List all available Yoro domains.
GET /api/v1/yoro/domains/
Source code in src/yoro/django/views.py
encode_view(request)
¶
Encode lat/lon to Altius Code.
GET /api/v1/yoro/encode/?lat=6.8&lon=-5.3&domain=CI&precision=12
Source code in src/yoro/django/views.py
precisions_view(request)
¶
List canonical precision levels for a domain.
GET /api/v1/yoro/precisions/?domain=CI&max_length=10