11

how ill, get my register based in the current (actual) month in my queryset?, i have a ModelManager(), that just show the LIVE register status, but now i want to show the register with LIVE status and in the current (actual) month, i know that ill make something like .filter(...), but i dont know how 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.

2 Answers 2

35

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)
1
  • 1
    That should be rewritten as MyModel.objects.filter(... the model itself doesn't have a filter method. Oct 2, 2009 at 8:27
0

That's if you are only interested in gettting the 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]
1
  • That's if you are only interested in gettting the month.....Hope it helps. Oct 19, 2018 at 22:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.