I am using mysql database and it's doesn't support list if I stored sting like "apple","banana" in my mysql database then when using get method fastapi how to convert theme from string to list like ["apple","banana"]. I tried this but didn't work and also not getting the image fields until I remove @property.
class Shop_page(BaseModel):
product_title: str
product_image: str
class Config():
orm_mode = True
@property
def product_image(self):
return self.product_image.split(",")
here is my get method
@router.get("/shop_page", response_model=List[schemas.Shop_page],status_code=status.HTTP_200_OK)
async def create_variations(db: Session = Depends(get_db)):
parent_item = db.query(models.ParentProduct).all()
return parent_item
my result look like now
[
{
"product_title": "DEMO PRODUCT",
"product_image": "image1_url,image2_url"
}
]
my expected result will be look like this
[
{
"product_title": "DEMO PRODUCT",
"product_image": ["image1_url,image2_url"]
}
]