Back

Pydantic Models for Collections

  • 0
  • Self Hosted
ZachHandley
29 Jul, 2023, 22:24

Hey, how do I create pydantic models for collections when $id is a field, because I can't use $id as a var name and Pydantic seems overly complex on trying to get it to work

TL;DR
The user is asking for help on creating Pydantic models for collections when the field name is `$id`. They tried using field aliases but encountered an issue. A suggestion was made to check the Pydantic documentation on field aliases. However, someone pointed out that the problem is actually not related to Appwrite and suggested seeking help on a Pydantic forum. The user provided their code snippet as an example. No solution was provided in the thread.
ZachHandley
29 Jul, 2023, 22:25
TypeScript

class Standard(BaseModel):
        id: str
    standardCode: str
    standardText: str
    topics: List[str]
    objectives: List[str]

        class Config:
            fields = { 'id': '$id' }

valid_data = Standard(data).dict(by_alias=True)
Drake
29 Jul, 2023, 22:50

Sounds fine but this isn't really an Appwrite question. Maybe a pydantic forum might be more helpful

ZachHandley
30 Jul, 2023, 03:51

well

ZachHandley
30 Jul, 2023, 03:52

the problem is the id's are stored as $id

Drake
30 Jul, 2023, 03:55

And?

Drake
30 Jul, 2023, 04:00
ZachHandley
30 Jul, 2023, 04:06

I did that, it then complained that id wasn't being set or something, we messed with it for 30-45 minutes before giving up and ust removing the ID

ZachHandley
30 Jul, 2023, 04:06

I was posting here hoping someone had tried to use a JSON Serializable class with their database fields because.. that's how it should be done

Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more