The view:
def GRID_ServerDropDownSearch(request):
if 'r' in request.GET and request.GET['r']:
r = request.GET['r']
servers = SERVERS.objects.get(name=r)
drives = servers.drives_set.all()[0:]
memory = servers.memory_set.all()[0:]
return render_to_response('GRID_ServerDropDownSearchResults.html',
{'servers':servers, 'query':r, 'drives':drives, 'memory':memory})
else:
return render_to_response('GRID_search_form.html', {'error': True})
The form:
class ServerDropDownForm(forms.Form):
r = forms.ModelChoiceField(queryset = SERVERS.objects.all(), required=False)
The template:
<div>
<form action="/ServerDropDownSearch/" method="GET">
{{ form.as_table }}
<input type = "Submit" value = "Submit">
</form>
</div>
The resulting drop-down form works flawlessly. However, immediately to the left of the drop-down list is an “R” (capital r). I know it has to do with the “r” specified in the above code. (If I replace each incidence of r with, say, z then a “Z” appears). However:
- WHY does it get capitalized ? Is this just the default case specified in the engine ?
- How can I hide that “R” so that, instead, it can indicate “Select A Server”, or something more descriptive.
Thanks in advance.
Django derives the label for a form field from the corresponding variable name, but “humanizes” it. For example, a field called
my_variablewould translate to “My variable”.The simplest way to fix this would be to give a more human-readable name to the field:
However, you can also pass a string to use as the label via the form field’s
labelparameter: