django-model-utilsããããã試ãã¦ã¿ã ãã®2 TimeFramedModel
昨日ã®ç¶ãã§django-model-utilsã試ãã¦ã¿ãã
ä»æ¥ã¯TimeFramedModelã
éå§æå»ã¨çµäºæå»ããã£ã¼ã«ãã«ãã¤ãããªã¢ãã«ã®å ´åã«ä½¿ããã
from model_utils.models import TimeFramedModel class Event(TimeFramedModel): name = models.CharField(max_length=100)
TimeFramedModelãç¶æ¿ããã¢ãã«ã¯startã¨endã¨ããååã®ãã£ã¼ã«ããæã¡ã¾ãã
from datetime import datetime, timedelta import pytz start = datetime.utcnow().replace(tzinfo=pytz.utc) - timedelta(days=1) end = datetime.utcnow().replace(tzinfo=pytz.utc) + timedelta(days=1) event = Event.objects.create(name='the event', start=start, end=end)
ã¾ãTimeFramedModelãç¶æ¿ããã¢ãã«ã¯timeframedã¨ããQueryManagerãæã¤ããã«ãªãã¾ãã
timeframedã¯ç¾å¨æå»ãstartã¨endã®ç¯å²å
ã§ããã¬ã³ã¼ããè¿ãã¾ãã
Event.timeframed.all() #=> [<Event: the event>] # æªæ¥ã®eventãç»é² start = datetime.utcnow().replace(tzinfo=pytz.utc) + timedelta(days=1) end = datetime.utcnow().replace(tzinfo=pytz.utc) + timedelta(days=2) event2 = Event.objects.create(name='future event', start=start, end=end) # æªæ¥ã®eventã¯è¿ãããªã Event.timeframed.all() #=> [<Event: the event>]
timeframedãæ´»èºããã±ã¼ã¹ã¯ããã¨æããã
é¢é£ : django-model-utilsããããã試ãã¦ã¿ã ãã®1 StatusModel - brainstorm
åè : carljm / django-model-utils / source / â Bitbucket