Wednesday, March 30, 2011

Re: inlineformset_factory default values

The problem I'm having is this. Those fields that I do not include in
my form attempt to update the DB, when the post data is missing those
values it blanks out those fields in the DB.

I have gotten around this by explicitly stating the fields I would
like to update but if I try to include data that cannot be updated via
the form (i.e. {{form.field.value}}) Then it will blank out the value
of that field. I don't, however, know how to access these values for
use in the template any other way. Here is my view code:

CampaignFormSet = inlineformset_factory(Race, Campaign,
can_delete=False, extra=0, max_num=0, fiel

r = get_object_or_404(Race, id=race_id)

if request.method == 'POST':
race_form = RaceForm(request.POST, instance=r)
if race_form.is_valid():
formset = CampaignFormSet(request.POST, instance=r)

if formset.is_valid():
instances =
for instance in instances:

return HttpResponseRedirect('')


formset = CampaignFormSet(instance=r)

here is the template

<form action="" method="POST">
{% for form in formset %}
{{}}<br />
<button type="submit"></button>
On Mar 30, 1:14 pm, Nick <> wrote:
> I am using inlineformsets_factory on a form and every time I save
> those fields that are not made available in the form are overridden to
> null values on save.
> How do i get it just to update those fields that are specifically
> listed in the form?

You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to
To unsubscribe from this group, send email to
For more options, visit this group at

No comments:

Post a Comment