14.
Profile Model과 OneToOneField
profile/models.py
class Profile(models.Model):
user = models.OneToOneField(settings.AUTH_USER_MODEL)
cash = models.IntegerField(defalut=0)
user.profile.cash 로 접근
http://perhapsspy.wordpress.com/2013/02/18/a-simple-way-how-to-extend-user-model-in-django-1-5/
15.
Profile 모델에 관련 함수 모으기
캐시 충전
캐시 환불
스토어 별 캐시
ex) user.profile.cash_charge(...)
16.
장점
다른 라이브러리와 충돌 걱정 없다.
관리도 쉽다.
구현이 제일 쉽다.
2가지 방법이 더 있으나
쉬운 게 최고…..는 아니고 상황에 맞게 찾아 쓰세요.
21.
HTML을 조각조각 따따따
template_name = ‘item_list.html’
if request.is_ajax():
template_name = ‘_item.html’
javascript는 최대한 단순하게.
하지만 아무래도 귀찮다. 맘에 들게 널 다시 조립할거야
22.
CBV로 한번 만들고 계속 쓰자.
반복 작업을 싫어하시는 당신을 위한
CBV - Class Based View
만들어둔 Class를 조립해서 쓴다.
https://docs.djangoproject.com/en/1.7/topics/class-based-views/
23.
Mixin을 써보자
class ChangeTemplateMixin(object):
# ajax 요청이 들어오면 template 변경
class MoreListMixin(ChangeTemplateMixin):
# 무한 스크롤 구현
class CashUseLogView(MoreListMixin, ListView):
# 위의 믹스인을 합쳐서 날로 먹기
class CashChargeLogView(MoreListMixin, ListView):
# 계속해서 날로 먹기
26.
Django REST framework
기능이 엄청 많습니다.
CBV로 API를 만들 수 있습니다.
즉, 모델만 잘 짜두면 순식간에 만듭니다.
단순한 API는 1~2시간이면 뚝딱.
하지만 속도가 느리다는 게 함정.
자세한 설명은 문서 참고하세요. 최근에 3.0까지 나왔습니다.
http://www.django-rest-framework.org/
38.
기타 다른 Admin 설정
list_display_links : 목록에서 누를 수 있는 링크가 되는 필드
list_per_page : 목록의 아이템 수
date_hierarchy : 지정한 날짜 필드 기준 필터 생성
ordering : 순서
search_fields : 검색 대상 필드
44.
그러니까,
● 모델이 제일 중요합니다.
● User 모델 확장은 OneToOne
● 소셜 로그인은 Django-allauth
● 반복 작업은 CBV
● DB최적화는 select_related, prefetch_related
● Cache는 컨트롤이 중요
● Admin는 django 핵심 기능입니다.
It appears that you have an ad-blocker running. By whitelisting SlideShare on your ad-blocker, you are supporting our community of content creators.
Hate ads?
We've updated our privacy policy.
We’ve updated our privacy policy so that we are compliant with changing global privacy regulations and to provide you with insight into the limited ways in which we use your data.
You can read the details below. By accepting, you agree to the updated privacy policy.