On Fri, Oct 30, 2009 at 2:58 PM, Anthony Simonelli
<asimonell...@gmail.com> wrote:
> On Fri, Oct 30, 2009 at 10:58 AM, Tom Evans <tevans...@googlemail.com> wrote:
>> When you iterate through the fieldset, you should be iterating through form
>> instances. Because they are forms from a ModelFormSet, they will be
>> ModelForm instances, and so will have an instance attribute that you can use
>> to output the fields you don't want in the form. You can then restrict the
>> fields that the formset will consider[1]
>>
>> Cheers
>>
>> Tom
>>
>> [1]
>> http://docs.djangoproject.com/en/dev/topics/forms/modelforms/#controlling-which-fields-are-used-with-fields-and-exclude
>>
>
> Okay,
>
> In my views.py I have the following:
>
> def entry(request)
>        ForecastEntryFormSet = modelformset_factory(ForecastActualSum, 
> fields=('forecast', ), extra=0)
>        forecasts = ForecastActualSum.objects.filter(sales_rep='5034',
> customer='1890').order_by('item')
>        formset = ForecastEntryFormSet(queryset = forecasts)
>        return render_to_response('forecast/entry.html', {'formset': formset})
>
> How do I access the instance attribute of the ModelForm instances
> within the template?  I've been able to do it from the Shell:
>

I apologize for not thinking about it further before I asked for more
help.  I specified only the field I want in the form when creating the
model formset as suggested above:

ForecastEntryFormSet = modelformset_factory(ForecastActualSum,
fields=('forecast', ), extra=0)

And then I accessed the instance in the Template using the following syntax:

<table border="1">

{% for form in formset.forms %}
{{ form.id }}
    <tr>
        <td>{{ form.instance.actual }}</td>
        <td>{{ form.forecast }}</td>
        <td>{{ form.instance.plan }}</td>
    </tr>
</tr>

{% endfor %}

</table>

<input type="submit" value="Save" />
</form>

This gave me exactly what I wanted and when I submitted the form, it
saved only that field!  Thank you for all of your help!

-Anthony

--~--~---------~--~----~------------~-------~--~----~
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