Hi,

I'm trying to use model formsets. At first, everything is normal. But when i
open the form page for the second time, i see that the formset is pre-filled
with the previous values. Here is my code:


models.py
---------------------------
class FooModel( models.Model ):

a_field = models.FloatField()
b_field = models.FloatField()

def __unicode__( self ):
return self.a_field

class CooModel( models.Model ):

c_field = models.CharField( blank=True,null=True,max_length = 100 )

def __unicode__( self ):
return u"%s" % ( smart_unicode(self.c_field))



forms.py
-------------------------------
from django.forms.models import modelformset_factory

FooFormSet = modelformset_factory(FooModel)

class CooModel_Form(ModelForm):

class Meta:
model = CooModel


views.py
-------------------------------
def new_func(request):

if request.method == 'POST':

formset = FooFormSet(request.POST, request.FILES, prefix='foo_prefix' )

if formset.is_valid():

formset.save()

return HttpResponseRedirect( '/true/' )

else:

return HttpResponseRedirect( '/false/' )

else:

formset = FooFormSet(prefix='foo_prefix')

variables = RequestContext( request , { 'formset':formset , } )

return render_to_response('yeni_alis_irsaliyesi.html' , variables )



template
------------------------------------
<form method="post" action=".">
{% csrf_token %}
<input type="submit" value="Submit" />
  <table id="FormsetTable" border="0" cellpadding="0" cellspacing="0">
  <tbody>
  {% for form in formset.forms %}
  <tr>
 <td>{{ form.a_field }}</td>
 <td>{{ form.b_field }}</td>
  </tr>
  {% endfor %}
  </tbody>
  </table>
  {{ formset.management_form }}
</form>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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