Hi Shawn,
Thanks for your reply. To begin with, I am trying this with a small test app.
I have this so far. I tried with two textarea elements on a page and tried to save them but I cannot figure out how to save two elements. Each element list corresponds to one model instance or table row for Text model. So, I need to have two save() in the view, correct?
Model:
class Text (models.Model):
name = models.CharField(max_length=1000)
text = models.TextField()
created_datetime = models.DateTimeField(auto_now_add=True, editable=False)
modified_datetime = models.DateTimeField(auto_now=True, editable=False)
active = models.BooleanField(default=True)
def __unicode__(self):
return self.name
class TextForm (ModelForm):
class Meta: model = Text
exclude = ('active','created_datetime', 'modified_datetime', )View:
def home(request): user = request.user
if request.method == 'POST': #Indvidual form value is accessible.
return HttpResponse(request.REQUEST['id_name_1'])
#I realized this is the usual model way which I cannot use
"""
text_form = TextForm(request.POST) if text_form.is_valid():
text_form.save() return render_to_response('home.html', {'user':user,})
else: return HttpResponse("text for not valid")
""" else:
text_form = TextForm() return render_to_response('home.html', {'text_form':text_form,})
Form:
<form method="post" id="text_form" action=".">
{% csrf_token %}
<div class="form">
<div class="form_added">
<!-- element set 1 -->
<fieldset id="fieldset1">
<p>
<label for="id_name_1">Name:</label>
<input id="id_name_1" type="text" name="id_name_1" maxlength="1000">
</p>
<p>
<label for="id_text_1">Text:</label>
<textarea id="id_text_1" rows="10" cols="40" name="id_text_1"></textarea>
</p>
<p>
<label for="id_active_1">Active:</label>
<input checked="checked" type="checkbox" name="id_active_1" id="id_active_1">
</p>
</fieldset>
</div>
<div class="form_added">
<!-- element set 2 --> <fieldset id="fieldset2">
<p>
<label for="id_name_2">Name:</label>
<input id="id_name_2" type="text" name="id_name_2" maxlength="1000">
</p>
<p>
<label for="id_text_2">Text:</label>
<textarea id="id_text_2" rows="10" cols="40" name="id_text_2"></textarea>
</p>
<p>
<label for="id_active_2">Active:</label>
<input checked="checked" type="checkbox" name="id_active_2" id="id_active_2">
</p>
</fieldset>
</div>
</div>
<p><input type="submit" value="Save folio" id="text_form_submit"/></p>
</form>
--
You received this message because you are subscribed to the Google Groups "Django users" group.