Hello all.

I use Django 1.1.

I try to make two formsets on the same page.
But  when I'm trying to use the data from POST, I have such problem:
from POST each formset takes only first form with value. Where have I
mistaken?

Sourse:

In views.py:
__________________
def results(request, countOfTerms, countOfUrls):
    def errorHandle(error):
        termFormSet = baseTermFormSet()
        urlFormSet = baseURLFormSet()
        return render_to_response('form.html', {
                'error' : error,
                'termFormSet' : termFormSet,
                'urlFormSet' : urlFormSet
        })
    countOfTermsNumber = int(countOfTerms)
    countOfUrlsNumber = int(countOfUrls)
    baseTermFormSet = formset_factory(TermForm,
formset=BaseTermFormSet, extra = countOfTermsNumber)
    baseURLFormSet = formset_factory(URLForm, formset=BaseURLFormSet,
extra = countOfUrlsNumber)
    if request.method == 'POST': # If the form has been submitted...
        termFormSet = baseTermFormSet(request.POST) # A form bound to
the POST data
        urlFormSet = baseURLFormSet(request.POST)
        if (termFormSet.is_valid() and urlFormSet.is_valid()): # All
validation rules pass
        #if True:
            terms = []
            urls = []

            for term in termFormSet._get_cleaned_data():
                terms.append(term['term'])
            for url in urlFormSet._get_cleaned_data():
                urls.append(url['url'])
            # Here we've couning TF for URL
            urlCounts = []
            for url in urls:
                termCounts = []
                termRefs = indexCount(url,terms)
                for i in range(len(terms)):
                    termCountRefs = []
                    termCountRefs.append(terms[i])
                    termCountRefs.append(termRefs[i])
                    termCounts.append(termCountRefs)


            return render_to_response('search.html',{
                                                     'terms':
termCounts,
                                                     'urls': urls
                                                     })
____________
In forms.py:
class BaseTermFormSet(BaseFormSet):

    def clean(self):
            if any(self.errors):
             # Don't bother validating the formset unless each form is
valid on its own
                return
            terms = []
            for i in range(0, self.total_form_count()):
                form = self.forms[i]
                term = form.cleaned_data['term']
                if term in terms:
                    raise forms.ValidationError, "Terms must be
different."
                terms.append(term)
            return terms

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

Reply via email to