2
You’re returning a list, not a queryset, from your manager method, so naturally none of the queryset methods like count and filter will work.
Edit
I’m not quite sure why you’re doing any of that. Seems like you just want to query the records between 12.00am and 11.59pm today, which is a simple query:
today = datetime.date.today()
start = datetime.datetime.combine(today, datetime.time(0))
end = datetime.datetime.combine(today, datetime.time(23, 59))
return self.filter(time_start__gte=start, time_start__lte=end)
0
As @Daniel Roseman wrote, I was returning a list when I needed to return a queryset. Just in case someone reads the question and wants to see the code that actually worked:
class RecordManager(models.Manager):
use_for_related_fields = True
def today(self, **kwargs):
today = datetime.datetime.now(pytz.utc)
reference_date = datetime.datetime(today.year, today.month, today.day, tzinfo=pytz.utc)
return self.filter(time_start__gte=reference_date, **kwargs)
- [Answer]-Django Assign Value To Model Form Before Validate
- [Answer]-Making queries for a single row table in Django
- [Answer]-Django admin delete != Model.delete()
- [Answer]-Django deployment https + gunicorn and nginx
- [Answer]-Displaying all photos in Album in list_display
Source:stackexchange.com