Django modelform validation is failing -


I can not understand the bug here. I have an integerfield on my model, whose field type is overridden at the respective model format. For the form, I have made the salary a Reggae field and added custom verification to eliminate any commas. I also tried to create a CharField ModelForm field without success Class Background_Check (models.Model): user = models.ForeignKey (user, exclusive = true) salary = model.Intergramefield ( Blank = True, Maximum_Long = 10) Square Background_CheckForm (forms.ModelForm): Pay = forms.RegexField (label = _ ("salary"), max_length = 10, regex = r '^ [\ d \ s] +', #help_text = _ ("Required .30 characters or fewer., Digits and @ /. / + / - / _ only."), Error_messages = {'invalid': _ ("Please enter a valid payday") }} Square Meta: Model = Background_Che Ck exclude = ('user') def returns salary

This is mine: salary = salary (self). View:

  @login_required def profile_settings (request): page = "account background" user = User.objects.get (pk = request.user.id) save_success = request.GET.get ( 'Save', '') Try: profile = user.background_check_set.all () [0] profileform = Background_CheckForm (instance = profile) except indexError: profile = '' profileform = Background_CheckForm () if request.method == 'POST Profile: profileform = background_heckForm (request.POST, example = profile) Other: profileform = Background_CheckForm (request.POST) if profileform.is_valid (): salary = profileform.cleaned_data [ 'Salary'] profile = profileform.save (commit = false) profile.user = user pr Ofile.save Returns HttpResponseRedirect ("/ account / profile / settings /? Save = 1") Other: return render_to_response ('website / profile_settings.html', {'page': page, 'profileform': profileofform}, context_instance = RequestContext (Request)): returning render_to_response ("website / profile_ settings.html", {'page': page, 'profile': profile, 'profileofform': profileform, 'save_success': save_success}, context_instance = RequestContext ))   

When I try to validate the model format, then I have an invalid IntegerField (this value is one full Should Nk) to get the standard error message. What's going on here

In your post, the clean_salary () method is not properly indented. This should be part of your Background_CheckForm class.

If your code is similar to your post, then the clean_slary () method is never implemented, and then you get a clear standard error message.

Comments