I have a small Django application with a form that saves some data in a database.
Here is the form:
class SomeForm(forms.Form):
time = forms.DateTimeField()
...
And the view where I save it:
class AccountAddIncome(View):
def save(self, form):
model = Model(
time=form.cleaned_data['time']
)
model.save()
def post(self, request, *args, **kwargs):
form = SomeForm(request.POST)
if form.is_valid():
self.save(form)
return redirect(self.success_url)
else:
...
My problem is that the Django administrator says: "Note: you are 1 hour ahead of server time."
The command dateon my Ubuntu (server) says exactly the same date as my computer.
But when I save this object to the database and make the following query:
Model.objects.filter(time__lt=timezone.now())
django does not list a previously saved model for an hour. If I go to the administrator and set the time back one hour, django'll show this object.
So my question is, what is the best way to manage datetime objects in django?
I want to save everything in UTC, but I cannot convert this datetime from form to UTC.