Last active
December 11, 2015 09:18
-
-
Save namongk/4579130 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# models.py | |
from django.db import models | |
class BusinessLog(models.Model): | |
STATUS = (('ING', 'Ongoing'), | |
('DONE', 'Done')) | |
status = models.CharField(choices=STATUS, default='ING') | |
# ref : https://docs.djangoproject.com/en/1.4/ref/models/fields/#django.db.models.Field.choices | |
# 를 참고하세요. | |
# 계속 이어서 작성을 합니다. | |
date_created = models.DateTimeField(auto_now_add=True) # 업무 최초 등록시 시간 자동 입력 | |
date_modified = models.DateTimeField(auto_now=True) # 업무 최종 변경 시간(save할 때마다 시간 자동 변경) | |
# 다른 필드는 생략했습니다. | |
############################################################################## | |
# views.py | |
# 직접 작성하셔도 되지만 이런 경우에는 generic view를 이용하는게 더 낫습니다. | |
from django.views.generic import TodayArchiveView, DayArchiveView | |
class TodayLogView(TodayArchiveView): | |
model = BusinessLog #임포트 한 모델 클래스 명을 적어 줍니다. | |
context_object_name = 'logs' # 템플릿에서 쓸 때 필요합니다. | |
date_field = 'date_created' | |
month_format = '%m' # 달을 숫자[01-12]형태로 표현합니다. | |
template_name = "myapp/businesslog_archive_today.html" # template > myapp > businesslog_archive_today.html이 있을 경우입니다. | |
class DailyLogView(DayArchiveView): | |
model = BusinessLog | |
context_object_name = 'logs' | |
date_field = 'date_created' | |
month_format = '%m' | |
template_name = "myapp/businesslog_archive_day.html" # | |
# ref : https://docs.djangoproject.com/en/1.5/ref/class-based-views/generic-date-based/#dayarchiveview | |
########################################################################### | |
# urls.py | |
from django.conf.urls import patterns, url | |
from myapp.views import TodayLogView, DailyLogView | |
urlpatterns = patterns('', | |
url(r'^work/today/$, TodayLogView.as_view(), name='archive_today'), | |
url(r'^work/(?P<year>\d{4})/(?P<month>\d{2})/(?P<day>\d{2})/$', DailyLogView.as_view(), name='archive_day') | |
) | |
# 대충 이렇게 작성하면 될 듯합니다. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment