I have a table with four or five foreign keys. Using the default form
widgets, a foreign key is represented by a single value select.

I noticed, with debug_tool_bar, that a query is being made for each
element of each foreign key select option. Seems like it ought not

I am using

    classes = get_object_or_404(Classes, pk=pk)

to load the record. I tried
Classes.on_site.select_related().get(pk=pk) without any change.

The question is, is this to be expected?


I'm using a fairly plain form:

{% extends 'district/district_edit_base.html' %}
{% block title %}
{{block.super}}
{% endblock title %}
{% block extra_ready_js %}
    {{block.super}}
     $("#district_list").collapse('show');
{% endblock extra_ready_js %}

{% block content %}
<form id="simple_form" method="post"
action="/staff/admin/classes/save/{{ id }}" class="form-horizontal">
    {% include "simple_fields.html" %}
</form>
{% endblock content %}

simple_fields is

<fieldset xmlns="http://www.w3.org/1999/html";>
{% csrf_token %}
{% for field in form %}
    <div class="control-group  {% if field.errors %} error {% endif%}">
        <label class="control-label"
for="id_{{field.name}}">{{field.label}}</label>
            <div class="controls">
              {{field}} <span class="field_help"> {{ field.help_text }}</span>
              <span class="help-inline">
                {{ field.errors }}
            </span>
            </div>
    </div>
{% endfor %}


<div id="submitButton" class="form-actions">
    {% if id != 0 %}
        <input type="hidden" name="Delete" id="real_delete" value="" />
        <input type="button" name="DeleteInit" id="DeleteInit"
value="Delete" class="btn btn-warning btn-delete" data-toggle="modal"
data-target="#modal-delete" data-backdrop="true" data-keyboard="true"
/>
    {% endif %}
    <span class="spacer">&nbsp;</span>
    <input type="submit" name="Submit" value="Save" class="btn btn-primary" />
    <span class="spacer">&nbsp;</span>

    <input type="button" name="return" id="return_to_list"
value="Return" title="Return to the list." class="btn" />
</div>
 </fieldset>

-- 
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+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to