2014-03-05 2 views
0

오늘부터 15 일 이후의 날짜 만 수락하고 시작 및 종료 시간을 저장하고 시작 시간 전에 종료 시간을 입력하면 오류가 표시되는 모델을 만들고 싶습니다.Django 모델 날짜 시간 필드

+0

그래서 ... 시작 시간은 더 빨리 오늘 + 15 일 이상이어야합니다 : 자세한 내용은

import datetime from django.core.exceptions import ValidationError from django.db import models class Article(models.Model): ... def clean(self): # Don't allow draft entries to have a pub_date. if self.status == 'draft' and self.pub_date is not None: raise ValidationError('Draft entries may not have a publication date.') # Set the pub_date for published items if it hasn't been set already. if self.status == 'published' and self.pub_date is None: self.pub_date = datetime.date.today() 

여기 읽을 ? – Brandon

+0

양식 검증 작업과 비슷합니다. 정말로 그것을 모델 레벨에 넣고 싶습니까? – alecxe

답변