Up until a couple days ago I have been using the following query succesfully. The following query has always returned the data it was supposed to return:
try:
totals = MyObject.objects.get(date=report_date)
except MyObject.DoesNotExist:
return HttpResponse('Could not find totals from %s' % (report_date))
A couple days ago this query began returning an empty QuerySet, even though data Does exist for the day I am requesting.
I am getting the date from report_date = date.today().strftime('%Y-%m-%d')
or from a form
if request.method == 'POST':
form = DateForm(request.POST)
if form.is_valid:
report_date = request.POST['date']
The Model is simple datefield()
class MyObject(models.Model):
"""Total numbers for a specific day"""
date = models.DateField()
... remaining fields ...
I have verified through the shell that there is in fact data for todays date in TotalTransactions. I have been using this code for months with no problem. I made a work around yesterday by querying
totals = MyObject.objects.get(date__gte=report_date, date__lte=report_date)
but this morning it no longer worked!! This morning I then tried the original query of date=report_date and that worked!
So my question is: Has anyone had this problem before?? Can anyone see something in my code that i am missing? Any suggestions on more workarounds? I appreciate your time.
why converting to the string? you do not have a control on how date is converted, eg. locale issues.
switch to
dateobjects and set in views only:and get data from the form’s
cleaned_datadict: