Sunday, May 30, 2010

Re: How to customize ModelChoiceField?

I think I've solved this myself.

I needed two fields for description: one for the description pk (in
case it is pre-existing) and one for the text.
I changed the widget for the description via RateForm.Meta.widgets to
a HiddenInput widget, and added the text field
to the form separately.

In RateForm.clean I do the necessary search for the description model
if there isn't one already defined, and setting the text of the model
in any case.

The override of ModelChoiceField may well be simple ... I started to
go down that road before I realized it wasn't what I wanted in any
case. What I do wonder (now out of curiosity) is how the queryset for
the ModelChoiceField gets set? E.g. I use the form to create a new
Rate. The pk from the Rate needs to find its way somehow to the
ModelChoiceField -- how? I don't see it in the forms.models code, but
perhaps I am missing it or its somewhere else.

Thanks, and good night!

--
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.

No comments:

Post a Comment