Saturday, December 4, 2010

Re: how can I clean a form field before the clean method?

> I want to do something like:
>
> aaaa.default = MyModel.objects.get(field=True)
>
> and raise an exception if don't find in the table a row with a field =
> True, but I don't have idea if something like this can be done.
>

I'm not always real good at understanding what someone wants.
However, it sounds as though you want to build a dynamic form (some
fields set dynamically, in response to certain conditions), but NOT
have the user mess with these things. The ways you mention to keep
the fields out of the form are the normal ways, but if you are going
to build a dynamic form without doing it in the POST view, etc., you
would normally do it with a custom __init__ method for the form. But
since the fields have been excluded, I think this would put you back
into the problem of marking form fields as hidden or something.

This kinda gets to be a circular problem primarily because the
function of a form is to accept user input, not hide it. I'm sure you
can do it, but it really just becomes a case (in my opinion) of
trying to pound a square peg into a round hole.

If I understand you correctly, my advice would be to validate the data
in clean(), and then to handle the object lookup in a pre_save()
signal catcher (in the model) and bail from there if the value isn't
found.

> Thanks for read and sorry for my newbies questions.

No apologies; we're all just talking and learning here ;) I hope I've
been able to contribute to the overall conversation.

--
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+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate