Update link referenecs #817
Unanswered
matteoarcangeli99
asked this question in
Question
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hello, this is part of my model structure
`class Economic_ID(BaseModel):
date: datetime
country: str
class Economic(Document):
id: Economic_ID
indicator1: float
indicator2: float
class Location_ID(BaseModel):
zip: str
country: str
lat: Optional[float] = None
lon: Optional[float] = None
class Location(Document):
id: Location_ID
economicIndicator: List[Link[Economic]]= []
`
I want to update economicIndicator based on new information that I got in the collection, so I have written this function, but it doent n't work. Can everyone help me?
async def update_economic_links(self): locations = await Location.find_many().to_list() location = locations[0] if locations else None If location is None: return None # Location not found economic_to_link = await Economic.find_many( Economic.id.country == "IT", ).to_list() await location.fetch_link(Location.economicIndicator) # Update the economicIndicator field location.economicIndicator = [Link(economic_id, Economic) for economic_id in economic_to_link] # Save the updated document await location.save() return location
Beta Was this translation helpful? Give feedback.
All reactions