怎么生病,根据我的查询集中的当前(实际)月份获取我的寄存器?,我有一个ModelManager(),只显示LIVE寄存器状态,但现在我想显示LIVE状态的寄存器当前(实际)月份,我知道生病了像.filter(...),但我不知道如何得到当月...
model.py
#manager
class LiveNoticiaManager(models.Manager):
def get_query_set(self):
return super(LiveNoticiaManager,self).get_query_set().filter(status=self.model.LIVE_STATUS)
谢谢你们。
答案 0 :(得分:20)
http://docs.djangoproject.com/en/dev/ref/models/querysets/#month
你可以
>>> import datetime
>>> today = datetime.date.today()
>>> MyModel.objects.filter(mydatefield__year=today.year,
mydatefield__month=today.month)
答案 1 :(得分:0)
导入日期时间
今天= datetime.date.today()
months = ['zero','January','February','March','April','May','June','July','August','September','October','November','December']
current_month = months[today.month]