Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django, actual month in queryset

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.

like image 205
Asinox Avatar asked Sep 13 '09 04:09

Asinox


1 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)
like image 113
Skylar Saveland Avatar answered Oct 28 '22 12:10

Skylar Saveland