Never mind - I changed it to ModelForm class instead.
>From what I have read, FormSet is not designed to be used in the
generic form way.
Rather for bulk adds or something like that.
ModelForm works nice and easy.


On Dec 21, 7:04 am, Michael Thamm <[email protected]> wrote:
> I am using 2 formsets on a template form and it shows fine but I don't
> know how to implement the form validation. Not allow a field to be
> empty.
> I have tried the basic method as documented but it doesn't trigger any
> messages.
> However, I also haven't put any defined errors anywhere so I don't
> know how an error message would appear.
> Bottom line is I don't understand the process and therefore can't set
> it up properly.
> If someone could show how to not allow the field
> {{ AddShirtFormSet.form.madeIn }} to NOT be empty, that would be a big
> help - thanks
>
> def addShirt(request):
>     AddShirtFormSet =
> modelformset_factory(Shirt,exclude=('create_date',))
>     AddUserShirtFormSet =
> modelformset_factory(UsersShirt,exclude=('shirt',))
>     if request.method == 'POST':
>         AddShirtFormSet = AddShirtFormSet(request.POST, request.FILES,
> prefix = 'shirt')
>         AddUserShirtFormSet = AddUserShirtFormSet(request.POST,
> request.FILES,prefix = 'usershirt')
>         if AddShirtFormSet.is_valid():
>             #formset.save()
>             # do something.
>             return HttpResponseRedirect('/shirt/') # Redirect after
> POST
>     else:
>         AddShirtFormSet = AddShirtFormSet(prefix = 'shirt')
>         AddUserShirtFormSet = AddUserShirtFormSet(prefix =
> 'usershirt')
>
>     return render_to_response("shirt/addshirt.html",
> RequestContext(request,{'AddShirtFormSet':
> AddShirtFormSet,'AddUserShirtFormSet': AddUserShirtFormSet,'error':
> True,}))
>
> *********** In template ****************
> <form name='AddShirt' method="post" action="/shirt/add/">
>   {{ form.non_field_errors }}
>   {% csrf_token %}
>   {{ AddShirtFormSet.management_form }}
>   {{ AddUserShirtFormSet.management_form }}
>   <div id="addFrom">
>
>     <div class="fieldWrapper">
>         {{ AddShirtFormSet.form.madeIn.errors }}
>         <label for="madeIn">Country made in?:</label>
>         {{ AddShirtFormSet.form.madeIn }}
>     </div>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to