0

I'm a newbie and right now I'm using Django forms to show some fields. One of these fields is a ModelChoiceField this show correctly model data, but I don“t know how I can fill a CharField later of select a option in the ModelChoiceField.

How I can make send the value of option selected for obtain the data that i need for later show this in a CharField, this is possible make directly from a djangoForm or do I need a new view to return the value?

1 Answers1

0

There are two ways to achieve what you want I think:

  1. Provide an initial value for your form value.
  2. Bind your form to some data.

See this related stack overflow to provide initial values.

See Django's documentation on forms for binding data. There are two kinds of form states: bound and unbound. To create a bound form, you just need to create an instance of your form with some data: MyForm({'data-key1': 'data-value1', ...}).

Community
  • 1
  • 1
generalpiston
  • 911
  • 7
  • 11