Django, the actual month in the query set

How bad is it to get my registry based on the current (actual) month in my query ?, I have ModelManager () that just shows the status of the LIVE register, but now I want to show the register with LIVE status in the current (actual) month , I know that I did something bad like .filter (...), but I don’t know how to get the current month.

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)

Thanks guys.

+5
source share
2 answers

http://docs.djangoproject.com/en/dev/ref/models/querysets/#month

You can

>>> import datetime
>>> today = datetime.date.today()
>>> MyModel.objects.filter(mydatefield__year=today.year,
                           mydatefield__month=today.month)
+20
source

If you are only interested in receiving a month:

import datetime

today = datetime.date.today()

months = ['zero','January','February','March','April','May','June','July','August','September','October','November','December']

current_month = months[today.month]
0
source

All Articles