Opened 9 years ago

Closed 8 years ago

#5852 closed (fixed)

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

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


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():

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:
Exception Type: 	OperationalError
Exception Value: 	(1366, "Incorrect integer value: '' for column 'takes_reservations' at row 1")

Change History (4)

comment:1 Changed 9 years ago by Brian Rosner

Needs documentation: unset
Needs tests: unset
Patch needs improvement: unset
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 Changed 9 years ago by whiskybar

Owner: changed from nobody to whiskybar
Status: newassigned

comment:3 Changed 9 years ago by whiskybar

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 Changed 8 years ago by JustinTArthur

Resolution: fixed
Status: assignedclosed

[7967] merged newforms-admin into trunk.

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