Opened 17 years ago

Closed 16 years ago

#5852 closed (fixed)

Setting models.NullBooleanField(null=True, blank=True)

Reported by: Ryan Kanno Owned by: whiskybar
Component: Forms Version: dev
Severity: Keywords:
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

I have a model that has the following:

takes_reservations = models.NullBooleanField(null=True, blank=True)

In my edit view I perform the following:

restaurant = Restaurant.objects.get_restaurant(slug, True)
RestaurantForm = forms.models.form_for_instance(restaurant, formfield_callback=restaurant_form_callback)
if request.method == 'POST':
    post_values = request.POST.copy()
    form = RestaurantForm(post_values)
    if form.is_valid():
        model.save()

Since the NullBooleanField maps to a CharField (why exactly I'm not sure ;P), if I fill in a value for the CharField, everything is ok. However, if the CharField is left blank, I get the following error:

OperationalError at /restaurants/my-restaurant/edit/
(1366, "Incorrect integer value: '' for column 'takes_reservations' at row 1")
Request Method: 	POST
Request URL: 	        http://wegoeat.com/restaurants/my-restaurant/edit/
Exception Type: 	OperationalError
Exception Value: 	(1366, "Incorrect integer value: '' for column 'takes_reservations' at row 1")

Change History (4)

comment:1 by Brian Rosner, 17 years ago

Triage Stage: UnreviewedAccepted

Yeah the problem here is that django.db.models.fields.NullBooleanField is not giving back the correct form field. It falls back to the default field class being a text box. I will see about getting a patch up here soon.

comment:2 by whiskybar, 17 years ago

Owner: changed from nobody to whiskybar
Status: newassigned

comment:3 by whiskybar, 17 years ago

This ticket will be closed when the trunk merges with the newforms-admin branch. It has been solved there for models.NullBooleanField and thus for each form_for_*

comment:4 by JustinTArthur, 16 years ago

Resolution: fixed
Status: assignedclosed

[7967] merged newforms-admin into trunk.

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