Answer the question
In order to leave comments, you need to log in
How to upload an image using python+pydentic?
I have something like this model in which data is generated for news on the portal:
class News:
id: int
name: str
image = Path
description: str
start_date: str
end_date: str
published: int
def generate_news_data(self) -> News:
text = text_generator.suffix_generator()
self.name: str = " Тестовая новость + "_" + suffix
self.image: Path = Path("news_portal_project/project/main/news_logo.png")
self.description: str = "Тестовое мероприятие"
self.start_date: str = date_settings.generate_date()
self.end_date: str = date_settings.generate_date(relative_delta=1)
self.published: int = 1
return self
def get_news_data(self) -> dict:
return {
"name": self.name,
"description": self.description,
"startDate": self.start_date,
"endDate": self.end_date,
"Published": self.published,
}
def get_news_files(self) -> AnyStr:
with open(self.image.absolute(), "rb") as file:
file.read()
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question