Opened 8 years ago

Closed 6 years ago

#5852 closed (fixed)

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

Reported by: ryankanno 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:

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

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Accepted

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

  • Owner changed from nobody to whiskybar
  • Status changed from new to assigned

comment:3 Changed 8 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 6 years ago by JustinTArthur

  • Resolution set to fixed
  • Status changed from assigned to closed

[7967] merged newforms-admin into trunk.

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