# Form select options values are there but cannto be seen

**URL:** <https://forum.djangoproject.com/t/form-select-options-values-are-there-but-cannto-be-seen/24885>\
**Category:** Templates & Frontend\
**Created:** [October 29, 2023, 10:13pm UTC](https://forum.djangoproject.com/t/form-select-options-values-are-there-but-cannto-be-seen/24885 "2023-10-29T22:13:45Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![jslovern391](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/jslovern391/32/16283_2.png) [@jslovern391](https://forum.djangoproject.com/u/jslovern391)\
**Post date:** [October 29, 2023, 10:13pm UTC](https://forum.djangoproject.com/t/form-select-options-values-are-there-but-cannto-be-seen/24885/1 "2023-10-29T22:13:45Z")

</div>

form

```auto
<div class="container mt-2">
    <form method="GET">
        {% csrf_token %}
        <h1><center>Transfer a Fish</center></h1><br>
        <select class="form-select">
            <option value="null">Select a Fisher</option>
            {% for sponsor in sponsors %}
            <option value="{{ sponsor.id }}">{{ sponsor.alias_name }}</option>
            {% endfor %}
          </select>
    
        <br><br><div>{{ form.as_p }}
        <input type="submit" value="Submit">
        </div> 
    </form>
    </div>

```

 ![image](https://us1.discourse-cdn.com/flex026/uploads/djangoproject/original/3X/2/6/2609d82d9c061c06fe591f694e9f2ef113d5310d.png)

The select has two options, I have tested it to have one and it shows one so the data is there, that can be selected but there is not text it is just blank.

---

<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:** [October 29, 2023, 10:16pm UTC](https://forum.djangoproject.com/t/form-select-options-values-are-there-but-cannto-be-seen/24885/2 "2023-10-29T22:16:18Z")

</div>

Please post the view that is rendering this template.

---

<div class="post-metadata">

**Author:** ![jslovern391](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/jslovern391/32/16283_2.png) [@jslovern391](https://forum.djangoproject.com/u/jslovern391)\
**Post date:** [October 29, 2023, 10:17pm UTC](https://forum.djangoproject.com/t/form-select-options-values-are-there-but-cannto-be-seen/24885/3 "2023-10-29T22:17:09Z")

</div>

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

Data is correct.

```auto
def fish_transfer(request):
    form = TransferFishForm

    sponsors = CustomUser.objects.filter(sponsor=request.user.id).filter(Q(status__range=(3,6))).values_list('id', 'alias_name')

    context = {
        'sponsors': sponsors,
    }
    return render(request, 'accounts/fish_transfer_form.html', context)

```

---

<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:** [October 29, 2023, 10:22pm UTC](https://forum.djangoproject.com/t/form-select-options-values-are-there-but-cannto-be-seen/24885/4 "2023-10-29T22:22:52Z")

</div>

Because you are using:

> [@jslovern391](#):
>
> `values_list('id', 'alias_name')`

the `sponsors` object is a queryset containing a list. This list does not associate attribute names with the values.

Remove the `values_list` function call from the query.

Side note: There are very few cases where you want to use that when rendering objects from models.

Side note 2: You don’t need to use two separate filter calls and you don’t need to wrap that second filter inside a `Q` object.

---

<div class="post-metadata">

**Author:** ![jslovern391](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/jslovern391/32/16283_2.png) [@jslovern391](https://forum.djangoproject.com/u/jslovern391)\
**Post date:** [October 29, 2023, 10:38pm UTC](https://forum.djangoproject.com/t/form-select-options-values-are-there-but-cannto-be-seen/24885/6 "2023-10-29T22:38:18Z")

</div>

Also is it possible to do this in a modal that is an item in a dropdown?

---

<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:** [October 29, 2023, 11:05pm UTC](https://forum.djangoproject.com/t/form-select-options-values-are-there-but-cannto-be-seen/24885/7 "2023-10-29T23:05:37Z")

</div>

Do what? I’m not understanding what you’re asking about.

---

<div class="post-metadata">

**Author:** ![jslovern391](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/jslovern391/32/16283_2.png) [@jslovern391](https://forum.djangoproject.com/u/jslovern391)\
**Post date:** [October 30, 2023, 5:24pm UTC](https://forum.djangoproject.com/t/form-select-options-values-are-there-but-cannto-be-seen/24885/8 "2023-10-30T17:24:15Z")

</div>

Right now I am using a template and was just curious if it could be a modal. Anyway, I am unable to get the value to show when I send it to a new view.

I select it in the select and submit and the queryset printed from the view sent to is empty.

```auto
<div class="container mt-2">
    <form >
        {% csrf_token %}
        <h1><center>Transfer a Fish</center></h1><br>
        <h3><center> {{ user.alias_name}}, you are requesting a transfer of {{ fish }} to: </center></h3><br>
        <div><center>
            <select class="form-select w-25" id="'new_sponsor">
                <option value="null">Select a Fisher</option>
                {% for new_sponsor in sponsors %}
                <option value="{{ new_sponsor.id }}">{{ new_sponsor.alias_name }}</option>
                {% endfor %}
            </select></center>
        </div><br><br>
        <center><a href="{% url 'fish_transfer_send' fish %}" class="btn btn-success">Transfer</button></a>
        <a href="{% url 'accounts/fish_list' %}" class="btn btn-danger">Cancel</button></a></center>
        </div> 
    </form>
    </div>

```

```auto
@login_required
def fish_transfer_send(request, fish):

    print(request.user.alias_name)
    print(fish)

```

```auto
path('fish_transfer_send/<str:fish>/', views.fish_transfer_send, name='fish_transfer_send'),

```

print output = jeff\_l0000, test\_u4789

 ![image](https://us1.discourse-cdn.com/flex026/uploads/djangoproject/original/3X/d/7/d7787c8adeb638d7a69bf7723af1183db61c4565.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:** [October 30, 2023, 6:44pm UTC](https://forum.djangoproject.com/t/form-select-options-values-are-there-but-cannto-be-seen/24885/9 "2023-10-30T18:44:29Z")

</div>

Your button is a button as a link - it is not a submit button and so it’s not submitting the form.

Regarding your question about modals, that’s a templating and JavaScript issue it has nothing to do with the view itself.

---

<div class="post-metadata">

**Author:** ![jslovern391](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/jslovern391/32/16283_2.png) [@jslovern391](https://forum.djangoproject.com/u/jslovern391)\
**Post date:** [October 30, 2023, 7:13pm UTC](https://forum.djangoproject.com/t/form-select-options-values-are-there-but-cannto-be-seen/24885/10 "2023-10-30T19:13:45Z")

</div>

form

```auto
class FishTransferForm(forms.Form):

    new_sponsor = forms.CharField(max_length=25)

    class Meta:
        fields = ('new_sponsor')

```

views

```auto
def fish_transfer(request, alias_name):
    sponsors = CustomUser.objects.filter(sponsor=request.user.id, status__range=(3,6)).values('id', 'alias_name')

    context = {
        'sponsors': sponsors,
        'fish': alias_name
    }
    return render(request, 'accounts/fish_transfer.html', context)

@login_required
def fish_transfer_send(self, form):
        form = FishTransferForm
        print(self)
        print(form.data)

```

URLs

```auto
path('fish_transfer/<str:alias_name>/', views.fish_transfer, name='fish_transfer'),

```

template

```auto
{% block body %}
    <div class="container mt-2">
    <form method="POST">
        {% csrf_token %}
        <h1><center>Transfer a Fish</center></h1><br>
        <h3><center> {{ user.alias_name}}, you are requesting a transfer of {{ fish }} to: </center></h3><br>
        <div><center>
            <select class="form-select w-25">
                <option value="null">Select a Fisher</option>
                {% for new_sponsor in sponsors %}
                <option value="{{ new_sponsor.id }}">{{ new_sponsor.alias_name }}</option>
                {% endfor %}
            </select></center>
        </div><br><br>
        <center><button type="submit">Transfer</button>
        <a href="{% url 'accounts/fish_list' %}" class="btn btn-danger">Cancel</button></a></center>
        </div> 
        {{ form.as_p }}
    </form>
    </div>
    {% endblock body %}

```

---

<div class="post-metadata">

**Author:** ![jslovern391](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/jslovern391/32/16283_2.png) [@jslovern391](https://forum.djangoproject.com/u/jslovern391)\
**Post date:** [October 30, 2023, 7:40pm UTC](https://forum.djangoproject.com/t/form-select-options-values-are-there-but-cannto-be-seen/24885/11 "2023-10-30T19:40:00Z")

</div>

It is not making it to the fish\_transfer\_send view.

[30/Oct/2023 15:38:37] “POST /accounts/fish\_transfer/test\_u4789/ HTTP/1.1” 200 5510

---

<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:** [October 30, 2023, 7:46pm UTC](https://forum.djangoproject.com/t/form-select-options-values-are-there-but-cannto-be-seen/24885/12 "2023-10-30T19:46:37Z")

</div>

You’re defining a form, but not using it at all - you could remove it. (Or, I would actually recommend using it.)

You don’t have a name on your `select` widget for the value to be submitted. (You’re rendering that widget manually - I’d suggest rendering it appropriately as a form.)

Your view doesn’t handle the posting of the form.

I suggest you review the docs at [Working with forms | Django documentation | Django](https://docs.djangoproject.com/en/4.2/topics/forms/) to gain an understanding of how Django works with forms and how you should interact with them.

---

<div class="post-metadata">

**Author:** ![jslovern391](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/jslovern391/32/16283_2.png) [@jslovern391](https://forum.djangoproject.com/u/jslovern391)\
**Post date:** [October 31, 2023, 11:17pm UTC](https://forum.djangoproject.com/t/form-select-options-values-are-there-but-cannto-be-seen/24885/13 "2023-10-31T23:17:23Z")

</div>

I think I am close to getting this. I have the form being rendered as a select but not getting the values. The two ways that I have seen it done is through context or importing the view in the forms. With the context, nothing shows, and with the import, I get a circular import error.

list view

```auto
def fishers_list(request):
    fishers = CustomUser.objects.filter(sponsor=request.user.id, status__range=(3,6)).values('alias_name').distinct('alias_name')

    fishers_list(request, fishers)

```

view with context

```auto
@login_required
def fish_transfer(request, alias_name):
    
    fishers = CustomUser.objects.filter(sponsor=request.user.id, status__range=(3,6)).values('alias_name').distinct('alias_name')
    
    if request.method == "POST":
        form = FishTransferForm(request.POST)
        print(request.POST)
        if form.is_valid():
            print(form.cleaned_data)
        return HttpResponse('<h1>Transfer Submitted</h1>')
    
    else:
        form = FishTransferForm()
    return render(request, 'accounts/fish_transfer.html', context = {'form':form, 'fishers':fishers, 'fish':alias_name})

```

form

```auto
class FishTransferForm(forms.Form):

    fishers = forms.ChoiceField(label='Select a Fisher', choices=[], widget=Select)
    
    class Meta:
        fields = ('fishers',)

```

template

```auto
 {% block body %}
    <div class="container mt-2">
    {% csrf_token %}
    <form method="POST" >
        {% csrf_token %}
        <h1><center>Transfer a Fish</center></h1><br>
        <h3><center> {{ user.alias_name}}, you are requesting a transfer of {{ fish }} to: </center></h3><br>
        <center>{{ form }}</center>
        </div><br><br>
        <center><button type="submit" class="btn btn-success">Transfer</button>
        <a href="{% url 'accounts/fish_list' %}" class="btn btn-danger">Cancel</button></a></center>
        </div> 
        
    </form>
    </div>
    
    {% endblock body %}

```

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

---

<div class="post-metadata">

**Author:** ![jslovern391](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/jslovern391/32/16283_2.png) [@jslovern391](https://forum.djangoproject.com/u/jslovern391)\
**Post date:** [October 31, 2023, 11:24pm UTC](https://forum.djangoproject.com/t/form-select-options-values-are-there-but-cannto-be-seen/24885/14 "2023-10-31T23:24:54Z")

</div>

Also, this is a way I have found form = FishTransferForm() by passing it in here. Can’t get it to work either.

---

<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:** [October 31, 2023, 11:57pm UTC](https://forum.djangoproject.com/t/form-select-options-values-are-there-but-cannto-be-seen/24885/15 "2023-10-31T23:57:29Z")

</div>

The fishers should be part of the form, it shouldn’t be something defined separately.

> [@jslovern391](#):
>
> ```auto
> class FishTransferForm(forms.Form):
> 
> fishers = forms.ChoiceField(label='Select a Fisher', choices=[], widget=Select)
> 
> ```

Your form needs to be defined to reference the options.

In practice, you would do this by using a ModelChoiceField instead of a ChoiceField.

I suggest you find some blogs, books, or other resources that show a complete example of creating and using a form. (See [GitHub - wsvincent/awesome-django: A curated list of awesome things related to Django](https://github.com/wsvincent/awesome-django#resources) for resources.)

Unfortunately, the official docs don’t provide a complete example that puts all the pieces together, so that’s actually not the best resource to see how it’s done in practice. There probably are a few examples here in the forum as well if you want to do some searching.

---

<div class="post-metadata">

**Author:** ![jslovern391](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/jslovern391/32/16283_2.png) [@jslovern391](https://forum.djangoproject.com/u/jslovern391)\
**Post date:** [November 1, 2023, 12:04am UTC](https://forum.djangoproject.com/t/form-select-options-values-are-there-but-cannto-be-seen/24885/16 "2023-11-01T00:04:05Z")

</div>

Thanks and I have been searching and have not them yet.
