UPDATE
This commit is contained in:
+7
-4
@@ -85,24 +85,27 @@ class PlantConfig(AppConfig):
|
||||
return self.growth_stage_aliases.get(normalized, value)
|
||||
|
||||
def resolve_plant_name(self, plant_name: str | None) -> str | None:
|
||||
from .models import Plant
|
||||
from farm_data.models import PlantCatalogSnapshot
|
||||
|
||||
value = (plant_name or "").strip()
|
||||
if not value:
|
||||
return value
|
||||
|
||||
plant = Plant.objects.filter(name=value).first() or Plant.objects.filter(name__iexact=value).first()
|
||||
plant = (
|
||||
PlantCatalogSnapshot.objects.filter(name=value).first()
|
||||
or PlantCatalogSnapshot.objects.filter(name__iexact=value).first()
|
||||
)
|
||||
if plant is not None:
|
||||
return plant.name
|
||||
|
||||
normalized = self._normalize_lookup_value(value)
|
||||
alias_target = self.plant_aliases.get(normalized)
|
||||
if alias_target:
|
||||
aliased_plant = Plant.objects.filter(name=alias_target).first()
|
||||
aliased_plant = PlantCatalogSnapshot.objects.filter(name=alias_target).first()
|
||||
if aliased_plant is not None:
|
||||
return aliased_plant.name
|
||||
|
||||
for plant in Plant.objects.only("name").iterator():
|
||||
for plant in PlantCatalogSnapshot.objects.only("name").iterator():
|
||||
if self._normalize_lookup_value(plant.name) == normalized:
|
||||
return plant.name
|
||||
|
||||
|
||||
Reference in New Issue
Block a user