[장고 어드민 삽질]

hyuckhoon.ko·2022년 7월 28일
0

1. 에러명

장고 어드민 페이지에서 에러가 발생했다.
처음 보는 에러였다. 원인이 짐작도 가지 않았다.

로컬 UI 테스트와 테스트 코드에서 발견되지 않았던 문제였다.
(물론 테스트가 에러 제로를 보장하지 않는다는 것은 너무나 잘 안다.
하지만 이번 배포는 자신있었다. 그래서 더더욱 쓰라렸다.)


2. Cast


3. Explicit is better than implicit

>>> import this
The Zen of Python, by Tim Peters

Beautiful is better than ugly.
Explicit is better than implicit.
Simple is better than complex.
Complex is better than complicated.
Flat is better than nested.
Sparse is better than dense.
Readability counts.
Special cases aren't special enough to break the rules.
Although practicality beats purity.
Errors should never pass silently.
Unless explicitly silenced.
In the face of ambiguity, refuse the temptation to guess.
There should be one-- and preferably only one --obvious way to do it.
Although that way may not be obvious at first unless you're Dutch.
Now is better than never.
Although never is often better than *right* now.
If the implementation is hard to explain, it's a bad idea.
If the implementation is easy to explain, it may be a good idea.
Namespaces are one honking great idea -- let's do more of those!

함축적인 것보다 명시적인 것이 더 좋다.
(Explicit is better than implicit)

Python Pro Tips: Understanding Explicit is Better than Implicit


4. 코드 수정

1) 개선 전


	def get_queryset(self, request): 
        (생략)
        .annotate(
                parsed_schedule=Min(
                        "match__schedule",
                        filter=Q(
                            match__status="RELEASE", 
                            match__schedule__gt=F("joined_at")
                        ),
                ),
         (생략)

2) 개선 후


	def get_queryset(self, request): 
        (생략)
        .annotate(
                parsed_schedule=Cast(
                    Min(
                        "match__schedule",
                        filter=Q(
                            match__status="RELEASE",
                            match__schedule__gt=F("joined_at")
                        ),
                    ),
                    DateTimeField(),
                ),
         (생략)

0개의 댓글