This is my view:
def perfilInversionCliente(request, cliente_pk):
objetos = {}
cliente = get_object_or_404(Cliente, pk=cliente_pk)
targetAllocationsForm = TargetAllocationsForm(cliente=cliente)
if request.method == "POST":
targetAllocationsForm = TargetAllocationsForm(request.POST)
if targetAllocationsForm.is_valid():
data = targetAllocationsForm.cleaned_data
for k in data:
editar = False
if isinstance(k, CategoriaActivo):
try:
currentAlloc = cliente.targetCategoriaAllocations.filter(
categoria=k).latest("fecha")
if currentAlloc.allocation != data[k]:
editar = True
except DoesNotExist:
editar = True
if editar:
newAlloc = TargetCategoriaAllocation(cliente=cliente, categoria=
k, allocation=data[k], fecha=datetime.datetime.now(), editor=request.user)
newAlloc.save()
if isinstance(k, SubcategoriaActivo):
try:
currentAlloc = cliente.targetSubcategoriaAllocations.filter(
subcategoria=k).latest("fecha")
if currentAlloc.allocation != data[k]:
editar = True
except DoesNotExist:
editar = True
if editar:
newAlloc = TargetSubcategoriaAllocation(cliente=cliente,
subcategoria=k, allocation=data[k], fecha=datetime.datetime.now(), editor=
request.user)
newAlloc.save()
else:
pdb.set_trace()
objetos["targetAllocationsForm"] = targetAllocationsForm
categorias = {}
for cat in CategoriaActivo.objects.all():
categorias[cat] = cat.subcategorias.all()
objetos["categorias"] = categorias
objetos["cliente"] = cliente
template = loader.get_template('carteras/perfilInversionista.html')
context = RequestContext(request, objetos)
return HttpResponse(template.render(context))
The keys of the form's fields are not strings, they are python objects...
At first I though that wouldn't work, but I tested the form in a shell and
it seems to work just fine.
On Monday, December 15, 2014 4:23:36 PM UTC-3, Daniel Roseman wrote:
>
> You should show your view.
>
> You should not call clean directly: it is called automatically by
> is_valid.
>
> Also note that the keys of self.fields are strings, so neither your if nor
> your elif will ever execute.
> --
> DR.
--
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 [email protected].
To post to this group, send email to [email protected].
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/4e60abe9-1955-4034-9e37-83179b9af03b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.