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, 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:

for form in formset.forms:
    form.instance.pk
    form.instance.item
    form.instance.sales_rep
    form.instance.customer
    form.instance.actual
    print form['forecast']
    form.instance.plan

Template so far:

{% if formset %}

<form action="" method="POST">

{{ formset.management_form }}

<table>

{% for form in formset.forms %}

    {% for field in form %}

    <tr><td>{{ field }}</td></tr>

    {% endfor %}

{% endfor %}

</table>

<input type="submit" value="Save" />
</form>
{% endif %}

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