Hey thanks a ton for this tutorial, im still quite new to django so I was wondering how would I go about adding a validation so at least one CollectionTitle is required for each Collection, thanks alot!
So I've figured out how to add validation for the CollectionTitle, but im doing it through views.py. Wondering if anybody knows how to add the validation to client side instead of going through views, thanks.
How I am doing it at the moment is adding a min_num and validate_min to the inlineformset_factory.
And by setting an else function in the form_valid. I save the object after validating titles since my project requires at least one title for each collection.
views.pyclassCollectionCreate(CreateView):#kept rest the same till form_valid
defform_valid(self,form):context=self.get_context_data()titles=context['titles']withtransaction.atomic():form.instance.created_by=self.request.useriftitles.is_valid():self.object=form.save()titles.instance=self.objecttitles.save()else:context.update({'titles':titles})returnself.render_to_response(context)returnsuper(CollectionCreate,self).form_valid(form)
Hey thanks a ton for this tutorial, im still quite new to django so I was wondering how would I go about adding a validation so at least one CollectionTitle is required for each Collection, thanks alot!
So I've figured out how to add validation for the CollectionTitle, but im doing it through views.py. Wondering if anybody knows how to add the validation to client side instead of going through views, thanks.
How I am doing it at the moment is adding a min_num and validate_min to the inlineformset_factory.
And by setting an else function in the form_valid. I save the object after validating titles since my project requires at least one title for each collection.
Great code! have been looking all day :/
This works for me