python - Django: Can't save empty form field to database - invalid literal for int() with base 10: '' -


many people report type of error, far none of fixes worked me. have model has integerfield allowing null values:

def somemodel(models.model):     ...     price_sell = models.integerfield(null=true)     ... 

then have form goes this:

class someform(forms.form):     ...     price_sell = forms.integerfield(required=false)     ... 

when leaving field empty, , calling save method, invalid literal int() base 10: '' error. tried many things having blank , null parameters, no luck far.

my solution has been views.py:

if form.is_valid():     if(request.post['price_sell'] == ''):         price_sell = none     ... 

but there more elegant way this. or there not?

i'm running django 1.6 on windows sqlite db.

grab data cleaned_data in form. integerfield want. form.cleaned_data['price_sell']


Comments

Popular posts from this blog

php - SPIP: From Tag directly to an article -

jquery - isAjaxRequest always return false -

ruby on rails - In a controller spec, how to find a specific tag in the generated view? -