Django count objects created in current month

django, django-models, django-orm

Solution

The (current) accepted answer is incorrect. As stated in comments, maybe OP wants current month in current year. Not current month in any year. Well most people want the first.

So I would rather do

Order.objects.filter(created_at__gte=timezone.now().replace(day=1, hour=0, minute=0, second=0, microsecond=0))

The above also gets around timezone issues.

Problem

I have field in my model: ``` class Order(BaseModel): created_at = models.DateTimeField(auto_now_add=True) ``` I need to count all Order objects created in current month. How can I do this in my views?

Original source