0👍
✅
Try this,
day_ago = datetime.date.today() - datetime.timedelta(days=1)
yesterday = datetime.datetime(day_ago.year, day_ago.month, day_ago.day)
hist_obj = Events.objects.filter(uploader = request.user,
start_date__lt = yesterday)
return render_to_response('history.html', {'history_obj':hist_obj})
1👍
This code is confusing. yesterday
and month
are both datetimes, because that’s how you defined them in lines 2 and 4. So what are you trying to achieve in the code that throws the error? As the message says, you can’t pass a datetime as the day or month parameter to construct another datetime. Especially as, surely, yesterday
is already the date that you want? Why can’t you simply pass that to the query?
- [Answer]-Dot operator for import 1.7 vs 1.8 style
- [Answer]-Django/mysql intermidiate table not inserting data
- [Answer]-Django: overriding save() method in model
- [Answer]-Django: Product attributes and custom fields form in product page
- [Answer]-Persistent Selection Multiselect Listbox Entries
Source:stackexchange.com