PostgreSQL – 조건에 IN 활용

Where 구문에 같은 것 말고 리스트에 포함된 걸로 조사할 때 사용하는 IN 이 있다.

용례가 갑자기 생각이 안나서 찾아봄

PostgreSQL IN operator examples

https://www.postgresqltutorial.com/postgresql-tutorial/postgresql-in/

Suppose you want to know the rental information of customer id 1 and 2, you can use the IN operator in the WHERE clause as follows:

`SELECT customer_id, rental_id, return_date `
`FROM rental `
`WHERE customer_id IN (1, 2) `
`ORDER BY return_date DESC;`

Python 파일 입출력 정리 – 한글, 인코딩

파이썬 파일 만들고 쓰고 읽고, 할때 마다 맨날 찾네.

한글 때문에 인코딩이 중요한 이슈 인듯! 아래 잘 정리된 사이트로 고고

https://24hours-beginner.tistory.com/115


# 한글깨짐 방지 ENCODING UTF-8
file = open("test.txt", "w", encoding="UTF-8")
file.write("내용입력")
file.close()

# 한글깨짐 방지2 ENCODING UTF-8
# txt는 UTF-8로도 충분한데 csv는 UTF-8로만 하면 읽을땐 다른걸로 읽을 경우 깨짐 현상 발생
file = open("test.csv", "w", encoding="UTF-8-sig")
file.write("test,test,test\n")
file.write("잘되나,안된다,오된다\n")
file.close()

Django admin timeouts – 외부키 로딩 시간 길어짐

Django admin 모델을 로드하는데 ForeignKey 로 선언한 부분에서, 외부키 데이터가 엄청 많아져서 이걸 셀렉트 선택창으로 로딩하는데 시간이 소모되어 admin 창이 안뜨고 timeout으로 에러 나는 경우가 발생!!!!

해결책이 다 있다. 수정이 안되게, readonly field 로 만들어서 로딩하는 것으로 해결!

> **readonly\_fields or raw\_id\_fields **

수정도 필요하다면, 아래 글 참고

How to fix Django admin timeouts

Have you ever noticed some Django admin page taking a long time to load? Maybe even ending in a timeout (http 504)?

https://engineering.loadsmart.com/blog/how-to-fix-django-admin-timeouts

원본글 일부 발췌

Use readonly_fields

In this situation, the easiest solution would be to just set those fields as readonly_fieldsin the page definition.

class CustomAdmin(admin.ModelAdmin):
    readonly_fields = (
        "some_field", # ForeignKey with lots of instances
    )

With it, the field will be rendered on the admin page just as its current value, statically.

Must be editable?

If having a foreign key as an editable field on the admin is a must for your use case, consider these options:

Use raw_id_fields

Setting the field as a raw id field still allows its editing as just the id value of the related entity:

class CustomAdmin(admin.ModelAdmin):
    raw_id_fields = (
        "some_field", # ForeignKey with lots of instances
    )

It will render an input field on the admin with the possibility of opening a popup to search for the desired instance