분류 전체보기66 django query filter, value, distinct 1. filter 만 했을 때와 , filter().values() 했을 때 차이. # This list contains a Blog object. >>> Blog.objects.filter(name__startswith='Beatles') # This list contains a dictionary. >>> Blog.objects.filter(name__startswith='Beatles').values() 원하는 속성값만 가지고 오고 싶을 땐, 매개변수로 속성값을 넣어서 가져온다.>>> Blog.objects.values() >>> Blog.objects.values('id', 'name') 2. distinct()¶distinct(*fields)¶ SQL 문에서 SELECT DISTINCT 한 것과.. 2018. 3. 28. django query Django에서 쿼리셋 효과적으로 사용하기 http://raccoonyy.github.io/using-django-querysets-effectively-translate/ tree_set = Tree.objects.filter(type="deciduous") # exists()는 쿼리셋 캐시를 만들지 않으면서 레코드가 존재하는지 검사한다 if tree_set.exists(): # DB에서 가져온 레코드가 하나도 없다면 # 트래픽과 메모리를 절약할 수 있다 print("There are still hardwood trees in the world!")star_set = Star.objects.all() # iterator() 메서드는 전체 레코드의 일부씩만 DB에서 가져오므로 # 메모리를 절약할 수 있다.. 2018. 3. 28. [2018_03_27] 찾아본 것 1. django admin 에서 model 추가하는 것from django.contrib import admin from .models import Question admin.site.register(Question) 2. mysql 기본 명령어 정리http://kwonnam.pe.kr/wiki/database/mysql/basic 3. centos7 mysql 설치http://pseg.or.kr/pseg/infoinstall/8335 4. django error django.db.utils.OperationalError: table table has no column named attribute1DB를 수정 후 migration 했는데 없다고 나옴;; migrations 폴더에 생기는 파일들 삭제 후.. 2018. 3. 27. inconsistent use of tabs and spaces in indentation 에러 해결 코드에서 들여쓰기도 잘하고 육안으로 볼때 잘못된 부분을 찾을 수 없는데계속 inconsistent use of tabs and spaces in indentation 에러가 나서 찾아보니,, 들여쓰기에서 탭과 스페이스를 혼용할 경우 나타납니다. 육안으로는 탭과 스페이스가 똑같이 느껴지지만 파이썬 인터프리터는 둘을 다르게 받아들입니다.탭으로 전체 들여쓰기를 통일하던지 아니면 스페이스로 들여쓰기를 통일하던지 하나로 맞춰주세요 라는 답변을 발견했다. 그래서 확인해보니,,들여쓰기 된 부분이, 스페이스바 + 탭 탭 + 탭 이렇게 되있었던것,,, 조심해야겠다! 출처 : https://programmers.co.kr/learn/questions/497 2018. 3. 27. 이전 1 ··· 5 6 7 8 9 10 11 ··· 17 다음