price_history = PriceHistory(
type="cpu",
part_id=existing_cpu.id,
start_date=datetime.datetime.now(),
price=price
)
price_history.save()
위 코드는 가격 추적 모델을 업데이트 하는 코드이다.
그런데 위 코드에서 업데이트 하는 시간을 저장할 때 날짜와 시간 정보만을 가지고 있고, 어떤 특정 시간대(time zone)와 관련된 정보가 없다.
그래서 아래와 같이 시간대에 관한 정보를 주어야한다. 그럼 더이상 나이브한 객체가 아니라 timezone-aware한 형식으로 저장된다.
price_history = PriceHistory(
type="cpu",
part_id=existing_cpu.id,
start_date=timezone.now(),
price=price
)
price_history.save()
'Django' 카테고리의 다른 글
MVT (0) | 2023.09.27 |
---|---|
네이버 Object Storage에 객체 업로드 하는 두 가지 방법 (0) | 2023.09.19 |
스레드와 GIL (0) | 2023.09.15 |
Django custom management command (0) | 2023.09.15 |
Requested setting LOGGING_CONFIG, but settings are not configured. (0) | 2023.09.13 |