#26174 closed Bug (invalid)
Validation fails for DateTimeField(widget= widgets.AdminSplitDateTime) in Django 1.9
| Reported by: | Josh | Owned by: | René Fleschenberg |
|---|---|---|---|
| Component: | Forms | Version: | 1.9 |
| Severity: | Normal | Keywords: | form validation |
| Cc: | rene@… | Triage Stage: | Accepted |
| Has patch: | no | Needs documentation: | no |
| Needs tests: | yes | Patch needs improvement: | no |
| Easy pickings: | no | UI/UX: | no |
Description
Validation for DateTimeField(widget= widgets.AdminSplitDateTime) fails in Django 1.9. The validation raised says: "Enter a valid date/time."
For Django 1.8 the validation is successful. Django 1.9 fails.
This is my form code:
from django import forms
from django.contrib.admin import widgets
class AddEventForm(forms.Form):
event_name = forms.CharField(max_length=30)
start_date = forms.DateTimeField(widget= widgets.AdminSplitDateTime)
This is the view:
from django.shortcuts import redirect, render_to_response, render
from django.views.generic.list import ListView
from .models import Events
from .forms import AddEventForm
class EventsListView(ListView):
model = Events
def new_event(request):
if request.method == 'POST':
form = AddEventForm(request.POST)
if form.is_valid():
save_data = form.cleaned_data
handler = Events(event_name=save_data['event_name'], start_date=save_data['start_date'])
handler.save()
return redirect('../')
else:
form_errors = form.errors
return render_to_response('events/error.html', {'form_errors': form_errors})
# if a GET (or any other method) we'll create a blank form
else:
form = AddEventForm()
return render(request, 'events/new_event_form.html', {'form': form})
My model:
from django.db import models
# Create your models here.
class Events(models.Model):
def __str__(self):
return self.event_name
event_name = models.CharField(max_length=30)
start_date = models.DateTimeField()
I attached a sample project (Admin App admin:admin)
Attachments (1)
Change History (6)
by , 10 years ago
| Attachment: | TestApp.tar.gz added |
|---|
comment:1 by , 10 years ago
| Owner: | changed from to |
|---|---|
| Status: | new → assigned |
comment:2 by , 10 years ago
| Needs tests: | set |
|---|---|
| Triage Stage: | Unreviewed → Accepted |
I can reproduce this. Looks like a regression to me. I will try to take a closer look at this soon.
comment:3 by , 10 years ago
I'm I remember correctly usage of SplitDateTimeWidget (and subclasses) with DateTimeField is deprecated since Django 1.7.
Can you also reproduce using SplitDateTimeField instead of DateTimeField?
comment:4 by , 10 years ago
| Resolution: | → invalid |
|---|---|
| Status: | assigned → closed |
Correct, the 1.9 release notes say, "The ability to use a SplitDateTimeWidget with DateTimeField is removed."
comment:5 by , 10 years ago
Ooops, sorry. I had only checked the "Backwards incompatible changes" section, not "Features removed" :)
SampleApp with validation error