@daler_xusinov · Post #318 · 28.10.2021 г., 16:25
#uiux Landing page design copy 1x1! Telegram | Blog | Portfolio
Hashtags
TGINSIGHT SIMILAR POSTS
Изворен канал @pythonotes · Post #397 · 12 ное.
Использование Pydantic сегодня стало нормой, и это правильно. Но иногда на ревью вижу, что используют его не всегда корректно. Например, метод BaseModel.model_dump() по умолчанию не преобразует стандартные типы, такие как datetime, UUID или Decimal, в простой сериализуемый для JSON вид. Тогда пишут кастмоный сериализатор для этих типов чтобы функция json.dump() не падала с ошибкой. import uuid from datetime import datetime from decimal import Decimal from uuid import UUID from pydantic import BaseModel class MyModel(BaseModel): id: UUID date: datetime value: Decimal obj = MyModel( id=uuid.uuid4(), date=datetime.now(), value='1.23' ) print(obj.model_dump()) # не подходит для json.dump # { # 'id': UUID('4f8c1bc4-25fd-40cd-9dbe-2c73639b0dc1'), # 'date': datetime.datetime(2025, 12, 12, 12, 12, 12, 111111), # 'value': Decimal('1.23') # } # добавляем свой кастомный сериализатор json.dumps(obj.model_dump(), cls=MySerializer) # { # 'id': '4f8c1bc4-25fd-40cd-9dbe-2c73639b0dc1', # 'date': '2025-12-12T12:12:12.111111', # 'value': '1.23' # } В данном случае класс MySerializer обрабатывает datetime, UUID и Decimal. Например так: class MySerializer(json.JSONEncoder): def default(self, o): if isinstance(o, Decimal): return str(o) elif isinstance(o, datetime): return o.isoformat() elif isinstance(o, UUID): return str(o) return super().default(o) Специально для тех, кто всё еще так делает - в этом нет необходимости! Pydantic может это сделать сам, просто нужно добавить параметр mode="json". json.dumps(obj.model_dump(mode="json")) # { # 'id': '4f8c1bc4-25fd-40cd-9dbe-2c73639b0dc1', # 'date': '2012-12-12T12:12:12.111111', # 'value': '1.23' # } #pydantic#libs
Пребарај: #uiux
@daler_xusinov · Post #318 · 28.10.2021 г., 16:25
#uiux Landing page design copy 1x1! Telegram | Blog | Portfolio
Hashtags
@Ai_artz · Post #1036 · 22.04.2023 г., 10:50
#from#UIUX A clean website landing page for a financial services firm that offers solutions on investments and insurance, use a gold dominant color and white color scheme --v 5 --ar 9:16 ✅ Miami _Discord @ai_artz🌿
@Ai_artz · Post #935 · 10.04.2023 г., 18:16
#from#UIUX An about me page of an online portfolio for a ui/ux desiger, Landing page, magazine style, urban, modern – ar 4:3 – v 5 ✅yoitsmarco#0012 _Discord Join us for more @ai_artz
@Ai_artz · Post #661 · 19.03.2023 г., 09:11
#from#UIUX Portfolio web site designe ✅ deadrk#8928 _Discord @ai_artz
@Ai_artz · Post #652 · 17.03.2023 г., 07:55
#from#UIUX ✅ Guyp _Twitter @ai_artz
@Ai_artz · Post #198 · 31.01.2023 г., 11:29
#from#UIUX ✅ @ LinusEkenstam _Twitter @ai_artz
@fidostudio · Post #16 · 01.12.2021 г., 15:42
Website for Juru Energy from UK. Juru Energy solution-oriented international consulting and engineering firm focused on the energy sector. #web#uiux Follow us: Telegram · Instagram · Dribbble
@fidostudio · Post #15 · 01.12.2021 г., 15:40
Tezkor is a service for ordering fast delivery of food from restaurants and groceries through mobile applications or a website. #web#uiux Follow us: Telegram · Instagram · Dribbble
@fidostudio · Post #9 · 01.12.2021 г., 13:04
Landing pages for Fermopolis. It is an online platform that allows farmers to raise finance, grow agricultural products and then supply them to consumers or return a percentage of sales. #web#uiux Follow us: Telegram · Instagram · Dribbble
@fidostudio · Post #14 · 01.12.2021 г., 15:39
Tezkor is a service for ordering fast delivery of food from restaurants and groceries through mobile applications or a website. #mobile#uiux Follow us: Telegram · Instagram · Dribbble
@fidostudio · Post #11 · 01.12.2021 г., 13:12
Special vaccination App for Covid 19. This App will help you to plan ahead the time, place and type of vaccination. Check out our new work 🙌 Link in bio. #app#uiux Follow us: Telegram · Instagram · Dribbble
@fidostudio · Post #22 · 01.12.2021 г., 16:00
New Interface for iABS. #web#uiux#3D Follow us: Telegram · Instagram · Dribbble