@@ -154,7 +154,18 @@ def _apply_fields(row, data: dict[str, Any], model) -> None:
|
||||
elif key not in ("enterprise_id", "created_at", "id"):
|
||||
extra[key] = value
|
||||
if model is ZootechRecipe and "ingredients" in data:
|
||||
row.payload_json = json.dumps(data.get("ingredients"), ensure_ascii=False)
|
||||
preserved: dict[str, Any] = {}
|
||||
if row.payload_json:
|
||||
try:
|
||||
existing = json.loads(row.payload_json)
|
||||
if isinstance(existing, dict) and existing.get("dispenser_id"):
|
||||
preserved["dispenser_id"] = existing["dispenser_id"]
|
||||
except json.JSONDecodeError:
|
||||
pass
|
||||
if preserved:
|
||||
row.payload_json = json.dumps(preserved, ensure_ascii=False)
|
||||
else:
|
||||
row.payload_json = json.dumps(data.get("ingredients"), ensure_ascii=False)
|
||||
elif extra and "payload_json" in allowed:
|
||||
row.payload_json = json.dumps(extra, ensure_ascii=False)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user