Hello,

I have the following Form:

class TargetAllocationsForm(forms.Form):
  def __init__(self, cliente, *args, **kwargs):
    super(TargetAllocationsForm, self).__init__(*args, **kwargs)
    for cat in CategoriaActivo.objects.all():
      self.fields[cat] = forms.FloatField(label=cat.nombre, min_value=0, 
max_value=1)
      try:
        currentAlloc = cliente.targetCategoriaAllocations.filter(categoria=
cat).latest("fecha")
        self.fields[cat].initial = currentAlloc.allocation
      except:
        self.fields[cat].initial = cat.default_allocation
    for sca in SubcategoriaActivo.objects.all():
      self.fields[sca] = forms.FloatField(label=sca.nombre, min_value=0, 
max_value=1)
      try:
        currentAlloc = cliente.targetSubcategoriaAllocations.filter(
subcategoria=sca).latest("fecha")
        self.fields[sca].initial = currentAlloc.allocation
      except:
        self.fields[sca].initial = sca.default_allocation

  def clean(self):
    cleaned_data = super(TargetAllocationsForm, self).clean() # Here is 
where I think the error is being raised
    allocations = {}
    for k in self.fields.keys():
      if isinstance(k, CategoriaActivo):
        if k not in allocations:
          allocations[k] = {"subcategorias":{}}
        allocations[k]["alloc"] = cleaned_data.get(k)
      elif isinstance(k, SubcategoriaActivo):
        if k.categoria not in allocations:
          allocations[k] = {"subcategorias":{}}
        allocations[k.categoria]["subcategorias"][k] = cleaned_data.get(k)

    total_allocations_cat = 0
    for cat in allocations:
      total_allocations_cat += allocations[cat]["alloc"]
      total_alloc_subcat = 0
      for subcat in allocations[cat]["subcategorias"]:
        total_alloc_subcat += allocations[cat]["subcategorias"][subcat]
      if total_alloc_subcat > 1:
        raise forms.ValidationError("Total de allocations en subcategorías 
de %s supera el 100%" % str(cat))
    if total_allocations_cat > 1:
      raise forms.ValidationError("Total de allocations en categorías 
supera el 100%")



When receiving the form in request.POST, I call the form.is_valid() method 
and it returns False, but no errors on the form. If I manually call 
form.clean() method (using pdb.set_trace() just after form.is_valid()) I get

*** AttributeError: 'TargetAllocationsForm' object has no attribute 
'cleaned_data'.

I would very much appreciate any help here

Greetings,
Hector.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/35e095fd-7283-424b-a2fe-98d230893525%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to