# 현재 모델의 변경사항을 마이그레이션으로 생성
python manage.py makemigrations
# 데이터베이스에 반영되지 않은 마이그레이션을 반영
python manage.py migrate
=============================
# 마이그레이션 목록과 적용여부를 보여줌
python manage.py showmigration
SQL 안쓰고 Pythjon으로 DB를 조작할 수 있도록 하는 것
# 생성
article = Article()
article.title = "첫번째 기사"
article.content = "본문"
article.save()
# 조회
Article.objects.get(content='my_content') # 두개 리턴되어 에러
->
Article.objects.get(id=1)
# 수정
article = Article.objects.get(id=1)
article.title = 'updated title'
article.save()
# 삭제
article = Article.objects.get(id=1)
article.delete()
# 2보다 큰 id
Article.objects.filter(id__gt=2)
# 1, 2, 3에 속하는 id
Article.objects.filter(id__in=[1, 2, 3])
Article.objects.filter(content__contains='my')
form을 POST요청으로 넣는다면
csrf 토큰을 넣는 것이 디폴트
GENRE_CHOICES = [
("technology", "Technology"), # 실제 DB에 저장될 값, 보여질 값
("life", "Life"),
("hobby", "Hobby"),
]
genre = forms.ChoiceField(choices=GENRE_CHOICES)
settings.py에서 확인 가능
인증과 권한을 합쳐서 Auth라 함
쿠키
세션과 쿠키가 쓰이는 방법
-> 쿠키에 민감한 정보를 저장할 필요 없이 session id만 저장하고 서버에서 검증하는 방식으로 사용함
-> 로그인은 이러한 절차로 구현됨
쿠키의 수명
blank=True # form에서 해당 값을 입력하지 않아도 괜찮음
null = True # Text가 저장되는 컬럼에서는 권장되지 않는 사항
역참조하는 옵션 : (Article -> Comment), article.comment_set.all()
comment_set이 아닌 comments로 하고 싶다면? -> comment의 article에 related_name에 "comments"를 명시
Logical routung
여러 DB에서 검색해야 하는 경우 -> datasources를 리스트 형태로 넣어주면 됩
Semantic routing