# Initialize forms.Select wizard

**URL:** <https://forum.djangoproject.com/t/initialize-forms-select-wizard/37115>\
**Category:** Forms & APIs\
**Created:** [December 9, 2024, 9:36pm UTC](https://forum.djangoproject.com/t/initialize-forms-select-wizard/37115 "2024-12-09T21:36:01Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![dave0823](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/dave0823/32/25689_2.png) [@dave0823](https://forum.djangoproject.com/u/dave0823)\
**Post date:** [December 9, 2024, 9:36pm UTC](https://forum.djangoproject.com/t/initialize-forms-select-wizard/37115/1 "2024-12-09T21:36:02Z")

</div>

I would like to initialize a form field (owner) with a 2-tuple in get\_form\_initial. For testing purposes, I’ve hardcoded initial to the tuple, but the owner select field is never populated. I eventually will retrieve data from the db for initializing the owner field.

However, I am able to initialize the owner field with a single value when forms.Select is changed to forms.TextInput, but never with a 2-tuple when owner is defined as a forms.Select.

I will really appreciate any help on this.

Thanks

models.py (partial)

![image](https://us1.discourse-cdn.com/flex026/uploads/djangoproject/original/3X/e/9/e92d0bf6e6a6205353437387e77a043bfe389805.png)

forms.py (partial)

![image](https://us1.discourse-cdn.com/flex026/uploads/djangoproject/original/3X/9/0/90b68b8b2765023197e3bf7ff665bb20fea822f5.png)

views.py

 ![image](https://us1.discourse-cdn.com/flex026/uploads/djangoproject/original/3X/1/b/1b15fdd1c609cdab6e0b8b06608d0d0d510a5cc0.png)

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [December 9, 2024, 9:55pm UTC](https://forum.djangoproject.com/t/initialize-forms-select-wizard/37115/2 "2024-12-09T21:55:06Z")

</div>

The initial data for a form represent the existing values of the data, not the options available to be selected.

Where are you setting the `choices` attribute for the `owner` field?

---

<div class="post-metadata">

**Author:** ![dave0823](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/dave0823/32/25689_2.png) [@dave0823](https://forum.djangoproject.com/u/dave0823)\
**Post date:** [December 9, 2024, 10:34pm UTC](https://forum.djangoproject.com/t/initialize-forms-select-wizard/37115/3 "2024-12-09T22:34:06Z")

</div>

Ken, still learning Django, but now I understand.

I initially thought I could just define the model and form field, and then in the wizard step, pre-populate the owner field in the form. Would it be best to perform a queryset in the form, and then assign the choice values to owner?

Thanks for your assistance!

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [December 9, 2024, 10:39pm UTC](https://forum.djangoproject.com/t/initialize-forms-select-wizard/37115/4 "2024-12-09T22:39:34Z")

</div>

I’m not sure I’m quite following you. You _can_ prepopulate the value of the owner field. However, if the field is a Select field, then the value being set must be one of the choices.

When you use a Select field, it will assign the value selected in the form to the model field. That’s not something you need to do yourself.

---

<div class="post-metadata">

**Author:** ![dave0823](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/dave0823/32/25689_2.png) [@dave0823](https://forum.djangoproject.com/u/dave0823)\
**Post date:** [December 9, 2024, 10:52pm UTC](https://forum.djangoproject.com/t/initialize-forms-select-wizard/37115/5 "2024-12-09T22:52:31Z")

</div>

Thanks, Ken. I’m going to investigate changing owner to ChoiceField.

Cheers

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [December 9, 2024, 11:17pm UTC](https://forum.djangoproject.com/t/initialize-forms-select-wizard/37115/6 "2024-12-09T23:17:25Z")

</div>

Again, I’m not sure I’m following you here. First, I mistakenly called `Choice` field a “Select” field. (It’s a mistake I make often.) The field is a `Choice` field, the widget is the `Select` widget.

So there’s nothing to be “changed” here in the form.

---

<div class="post-metadata">

**Author:** ![dave0823](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/dave0823/32/25689_2.png) [@dave0823](https://forum.djangoproject.com/u/dave0823)\
**Post date:** [December 10, 2024, 1:11am UTC](https://forum.djangoproject.com/t/initialize-forms-select-wizard/37115/7 "2024-12-10T01:11:02Z")

</div>

Hi Ken, got it working!!! Much appreciated for your insight.

I changed my owner field to:

![image](https://us1.discourse-cdn.com/flex026/uploads/djangoproject/original/3X/4/f/4fb0bf5ca13ed54d528c39af1cd25d311acce7fd.png)

and it now updates dynamically. One issue though. I lost my formatting for my owner widget.

![image](https://us1.discourse-cdn.com/flex026/uploads/djangoproject/original/3X/b/3/b3d1cb55bca76833eb4d5c1882ace4f7dc58dcc1.png)

Any ideas how this can be implemented?

Thanks again!

Cheers

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [December 10, 2024, 1:31am UTC](https://forum.djangoproject.com/t/initialize-forms-select-wizard/37115/8 "2024-12-10T01:31:21Z")

</div>

Include the `attrs` attribute in your `forms.Select(` constructor with the `choices=...` attribute.

---

<div class="post-metadata">

**Author:** ![dave0823](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/dave0823/32/25689_2.png) [@dave0823](https://forum.djangoproject.com/u/dave0823)\
**Post date:** [December 10, 2024, 1:40am UTC](https://forum.djangoproject.com/t/initialize-forms-select-wizard/37115/9 "2024-12-10T01:40:37Z")

</div>

Formatting is back - thanks!

I did try this initially, but I inadvertently added the attributes outside of the enclosed “choices”, instead of within the Select params.

Take care, and thanks again.

Cheers,  
Dave
