Opened 16 years ago

Last modified 16 years ago

#9558 closed

datetime blank=True — at Version 1

Reported by: wim@… Owned by: nobody
Component: Uncategorized Version: 1.0
Severity: Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by Karen Tracey)

In a model, having a DateTimeField with blank = True, I get an error when leaving the value blank on saving.

My model is, simplified:

class Place(models.Model):
    name = models.CharField(max_length=100)

class Event(models.Model):
    user = models.ForeignKey(User)
    place = models.ForeignKey(Place, blank=True)
    starttime = models.DateTimeField(blank=True)

class EventForm(forms.ModelForm):
    class Meta:
        model = Event
        exclude = ['owner']

def edit_event(request, event_id=False):
    userid = request.session['loggedinas']
    if request.POST:
        event = EventForm(request.POST)
        if event.is_valid():
            cleaned_data = event.cleaned_data
            event = Event( user_id = userid )
            fields = ['name', 'description', 'starttime', 'endtime', 'photo', 'file']
            for fieldname in fields:
                setattr( event, fieldname, cleaned_data[fieldname])
                return HttpResponseRedirect('/success')
     ...

Change History (1)

comment:1 by Karen Tracey, 16 years ago

Description: modified (diff)

Reformatted description. Please use preview before posting. Also, it would be ever so much more helpful if you'd specify what exact error you get. Why leave us guessing with the vague "an error"?

Note: See TracTickets for help on using tickets.
Back to Top