Django, ValidationError in BaseModelFormSetWhat is a “slug” in Django?How do I do a not equal in Django queryset filtering?Does Django scale?What's the difference between django OneToOneField and ForeignKey?Saving form data rewrites the same rowDjango low level cache viewsdifferentiate null=True, blank=True in djangoDjango modelformset order_by not workingAccessing context variables in modelformunit testing django ModelFormset clean methods

Why did the metro bus stop at each railway crossing, despite no warning indicating a train was coming?

Why did the soldiers of the North disobey Jon?

How to check if comma list is empty?

c++ conditional uni-directional iterator

Can my American children re-enter the USA by International flight with a passport card? Being that their passport book has expired

Could there be something like aerobatic smoke trails in the vacuum of space?

Geometric inspiration behind Hal(irutan)'s Wolf(ram Language Logo)

Was the dragon prowess intentionally downplayed in S08E04?

Can anyone give me examples of the relative-determinative 'which'?

Slice a list based on an index and items behind it in python

Given 0s on Assignments with suspected and dismissed cheating?

Will consteval functions allow template parameters dependent on function arguments?

Why is the marginal distribution/marginal probability described as "marginal"?

Polynomial division: Is this trick obvious?

Does the Rogue's Reliable Talent feature work for thieves' tools, since the rogue is proficient in them?

Variance and covariance inequality

What dog breeds survive the apocalypse for generations?

Why did Varys remove his rings?

What is this weird d12 for?

Is there an academic word that means "to split hairs over"?

Why do galaxies collide?

When did game consoles begin including FPUs?

Can I say: "When was your train leaving?" if the train leaves in the future?

tikz drawing rectangle discretized with triangle lattices and its centroids



Django, ValidationError in BaseModelFormSet


What is a “slug” in Django?How do I do a not equal in Django queryset filtering?Does Django scale?What's the difference between django OneToOneField and ForeignKey?Saving form data rewrites the same rowDjango low level cache viewsdifferentiate null=True, blank=True in djangoDjango modelformset order_by not workingAccessing context variables in modelformunit testing django ModelFormset clean methods






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








0















I am using BaseModelFormSet and passed it to modelformset_factory in views.And inside BaseModelFormSet function i override clean() to make formset validation to rise validation error.The problem is that when I try to fill the formset with a wrong data, validation error is not showing at all



I have tried to render from in template manually with non field errors but did not work and went through documentation https://docs.djangoproject.com/en/2.1/topics/forms/modelforms/#overriding-clean-on-a-modelformset



UPDATE: if I intentionally filled the form with wrong data , it will validate only the first form in formset not all the fomrs (extras set to 2)



forms.py



class MyModelFormSet(BaseModelFormSet):
def clean(self):
super().clean()
if any(self.errors)
return

for form in self.forms:
debit = form.cleaned_data['debit']
if debit == 100:
raise forms.ValidationError('debit is 100!')
return debit


views.py



def postpage(request):
journalLineFormSet = modelformset_factory(journalLine,exclude=('journalNumber',),extra=2,can_delete=True,formset=MyModelFormSet,max_num=2,validate_max=True)
if request.method == 'POST':
mainform = journalForm(request.POST)
subform = journalLineFormSet(request.POST)
if mainform.is_valid() and subform.is_valid():
instances = subform.save(commit=False)
for instance in instances:
instance.save()
mainform.save()


return HttpResponseRedirect('/myacc/posted/')

else:
##linesform = linesform(queryset=journal.objects.all().none())
mainform = journalForm()
subform = journalLineFormSet(queryset=journalLine.objects.all().none()) #prefix used if you want to set a cumstom prefix to from name

return render(request,'myacc/post.html','mainform': mainform, 'subform': subform)









share|improve this question
























  • UPDATE: I have added this in template subform.non_form_errors and it works but only for the first form instance , I mean it is not work with the 2nd form.. I have set extras to 2 and I want the validation to work with 2nd form too

    – ramezamr
    Mar 23 at 17:57

















0















I am using BaseModelFormSet and passed it to modelformset_factory in views.And inside BaseModelFormSet function i override clean() to make formset validation to rise validation error.The problem is that when I try to fill the formset with a wrong data, validation error is not showing at all



I have tried to render from in template manually with non field errors but did not work and went through documentation https://docs.djangoproject.com/en/2.1/topics/forms/modelforms/#overriding-clean-on-a-modelformset



UPDATE: if I intentionally filled the form with wrong data , it will validate only the first form in formset not all the fomrs (extras set to 2)



forms.py



class MyModelFormSet(BaseModelFormSet):
def clean(self):
super().clean()
if any(self.errors)
return

for form in self.forms:
debit = form.cleaned_data['debit']
if debit == 100:
raise forms.ValidationError('debit is 100!')
return debit


views.py



def postpage(request):
journalLineFormSet = modelformset_factory(journalLine,exclude=('journalNumber',),extra=2,can_delete=True,formset=MyModelFormSet,max_num=2,validate_max=True)
if request.method == 'POST':
mainform = journalForm(request.POST)
subform = journalLineFormSet(request.POST)
if mainform.is_valid() and subform.is_valid():
instances = subform.save(commit=False)
for instance in instances:
instance.save()
mainform.save()


return HttpResponseRedirect('/myacc/posted/')

else:
##linesform = linesform(queryset=journal.objects.all().none())
mainform = journalForm()
subform = journalLineFormSet(queryset=journalLine.objects.all().none()) #prefix used if you want to set a cumstom prefix to from name

return render(request,'myacc/post.html','mainform': mainform, 'subform': subform)









share|improve this question
























  • UPDATE: I have added this in template subform.non_form_errors and it works but only for the first form instance , I mean it is not work with the 2nd form.. I have set extras to 2 and I want the validation to work with 2nd form too

    – ramezamr
    Mar 23 at 17:57













0












0








0








I am using BaseModelFormSet and passed it to modelformset_factory in views.And inside BaseModelFormSet function i override clean() to make formset validation to rise validation error.The problem is that when I try to fill the formset with a wrong data, validation error is not showing at all



I have tried to render from in template manually with non field errors but did not work and went through documentation https://docs.djangoproject.com/en/2.1/topics/forms/modelforms/#overriding-clean-on-a-modelformset



UPDATE: if I intentionally filled the form with wrong data , it will validate only the first form in formset not all the fomrs (extras set to 2)



forms.py



class MyModelFormSet(BaseModelFormSet):
def clean(self):
super().clean()
if any(self.errors)
return

for form in self.forms:
debit = form.cleaned_data['debit']
if debit == 100:
raise forms.ValidationError('debit is 100!')
return debit


views.py



def postpage(request):
journalLineFormSet = modelformset_factory(journalLine,exclude=('journalNumber',),extra=2,can_delete=True,formset=MyModelFormSet,max_num=2,validate_max=True)
if request.method == 'POST':
mainform = journalForm(request.POST)
subform = journalLineFormSet(request.POST)
if mainform.is_valid() and subform.is_valid():
instances = subform.save(commit=False)
for instance in instances:
instance.save()
mainform.save()


return HttpResponseRedirect('/myacc/posted/')

else:
##linesform = linesform(queryset=journal.objects.all().none())
mainform = journalForm()
subform = journalLineFormSet(queryset=journalLine.objects.all().none()) #prefix used if you want to set a cumstom prefix to from name

return render(request,'myacc/post.html','mainform': mainform, 'subform': subform)









share|improve this question
















I am using BaseModelFormSet and passed it to modelformset_factory in views.And inside BaseModelFormSet function i override clean() to make formset validation to rise validation error.The problem is that when I try to fill the formset with a wrong data, validation error is not showing at all



I have tried to render from in template manually with non field errors but did not work and went through documentation https://docs.djangoproject.com/en/2.1/topics/forms/modelforms/#overriding-clean-on-a-modelformset



UPDATE: if I intentionally filled the form with wrong data , it will validate only the first form in formset not all the fomrs (extras set to 2)



forms.py



class MyModelFormSet(BaseModelFormSet):
def clean(self):
super().clean()
if any(self.errors)
return

for form in self.forms:
debit = form.cleaned_data['debit']
if debit == 100:
raise forms.ValidationError('debit is 100!')
return debit


views.py



def postpage(request):
journalLineFormSet = modelformset_factory(journalLine,exclude=('journalNumber',),extra=2,can_delete=True,formset=MyModelFormSet,max_num=2,validate_max=True)
if request.method == 'POST':
mainform = journalForm(request.POST)
subform = journalLineFormSet(request.POST)
if mainform.is_valid() and subform.is_valid():
instances = subform.save(commit=False)
for instance in instances:
instance.save()
mainform.save()


return HttpResponseRedirect('/myacc/posted/')

else:
##linesform = linesform(queryset=journal.objects.all().none())
mainform = journalForm()
subform = journalLineFormSet(queryset=journalLine.objects.all().none()) #prefix used if you want to set a cumstom prefix to from name

return render(request,'myacc/post.html','mainform': mainform, 'subform': subform)






django django-models django-forms django-templates django-views






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 24 at 22:11







ramezamr

















asked Mar 23 at 15:33









ramezamrramezamr

16




16












  • UPDATE: I have added this in template subform.non_form_errors and it works but only for the first form instance , I mean it is not work with the 2nd form.. I have set extras to 2 and I want the validation to work with 2nd form too

    – ramezamr
    Mar 23 at 17:57

















  • UPDATE: I have added this in template subform.non_form_errors and it works but only for the first form instance , I mean it is not work with the 2nd form.. I have set extras to 2 and I want the validation to work with 2nd form too

    – ramezamr
    Mar 23 at 17:57
















UPDATE: I have added this in template subform.non_form_errors and it works but only for the first form instance , I mean it is not work with the 2nd form.. I have set extras to 2 and I want the validation to work with 2nd form too

– ramezamr
Mar 23 at 17:57





UPDATE: I have added this in template subform.non_form_errors and it works but only for the first form instance , I mean it is not work with the 2nd form.. I have set extras to 2 and I want the validation to work with 2nd form too

– ramezamr
Mar 23 at 17:57












0






active

oldest

votes












Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55315390%2fdjango-validationerror-in-basemodelformset%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55315390%2fdjango-validationerror-in-basemodelformset%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현