fix: allow null for Quantity.measure field
since apparently that is optional, e.g. for "Precipitation" quick form logs
This commit is contained in:
parent
913d5801cd
commit
fbae0bcfc8
3 changed files with 45 additions and 3 deletions
|
|
@ -0,0 +1,36 @@
|
||||||
|
"""allow null for quantity.measure_id
|
||||||
|
|
||||||
|
Revision ID: c30a725b54f9
|
||||||
|
Revises: a240a1449de9
|
||||||
|
Create Date: 2026-05-30 22:14:21.056993
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
from typing import Sequence, Union
|
||||||
|
|
||||||
|
from alembic import op
|
||||||
|
import sqlalchemy as sa
|
||||||
|
import wuttjamaican.db.util
|
||||||
|
|
||||||
|
|
||||||
|
# revision identifiers, used by Alembic.
|
||||||
|
revision: str = "c30a725b54f9"
|
||||||
|
down_revision: Union[str, None] = "a240a1449de9"
|
||||||
|
branch_labels: Union[str, Sequence[str], None] = None
|
||||||
|
depends_on: Union[str, Sequence[str], None] = None
|
||||||
|
|
||||||
|
|
||||||
|
def upgrade() -> None:
|
||||||
|
|
||||||
|
# quantity
|
||||||
|
op.alter_column(
|
||||||
|
"quantity", "measure_id", existing_type=sa.VARCHAR(length=20), nullable=True
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def downgrade() -> None:
|
||||||
|
|
||||||
|
# quantity
|
||||||
|
op.alter_column(
|
||||||
|
"quantity", "measure_id", existing_type=sa.VARCHAR(length=20), nullable=False
|
||||||
|
)
|
||||||
|
|
@ -109,7 +109,7 @@ class Quantity(model.Base):
|
||||||
measure_id = sa.Column(
|
measure_id = sa.Column(
|
||||||
sa.String(length=20),
|
sa.String(length=20),
|
||||||
sa.ForeignKey("measure.drupal_id"),
|
sa.ForeignKey("measure.drupal_id"),
|
||||||
nullable=False,
|
nullable=True,
|
||||||
doc="""
|
doc="""
|
||||||
Measure for the quantity.
|
Measure for the quantity.
|
||||||
""",
|
""",
|
||||||
|
|
@ -192,7 +192,12 @@ class Quantity(model.Base):
|
||||||
app = config.get_app()
|
app = config.get_app()
|
||||||
value = app.render_quantity(value)
|
value = app.render_quantity(value)
|
||||||
units = str(self.units or "")
|
units = str(self.units or "")
|
||||||
return f"( {measure} ) {value} {units}"
|
|
||||||
|
if measure:
|
||||||
|
return f"( {measure} ) {value} {units}"
|
||||||
|
|
||||||
|
label = self.label or ""
|
||||||
|
return f"{label} {value} {units}"
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.render_as_text()
|
return self.render_as_text()
|
||||||
|
|
|
||||||
|
|
@ -298,7 +298,8 @@ class QuantityMasterView(WuttaFarmMasterView):
|
||||||
f.remove("measure")
|
f.remove("measure")
|
||||||
else:
|
else:
|
||||||
f.set_readonly("measure")
|
f.set_readonly("measure")
|
||||||
f.set_default("measure", quantity.measure.name)
|
if quantity.measure:
|
||||||
|
f.set_default("measure", quantity.measure.name)
|
||||||
|
|
||||||
# value
|
# value
|
||||||
if self.creating:
|
if self.creating:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue