I do realize that I need the number of elements so that I can loop over that
many times...

On Sun, Jul 3, 2011 at 4:30 PM, AJ <brandmys...@gmail.com> wrote:

> 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>
>
>
>
> On Sun, Jul 3, 2011 at 1:40 PM, Shawn Milochik <sh...@milochik.com> wrote:
>
>> As long as, when you instantiate your Django forms.Form instance when the
>> HTML form is posted, you create the fields passed in the form data and
>> instantiate the fields to match you should be fine.
>>
>> Just go ahead and do it, and if you run into any snags post to the forum.
>>
>> Shawn
>>
>>
>> --
>> 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+unsubscribe@**
>> googlegroups.com <django-users%2bunsubscr...@googlegroups.com>.
>> For more options, visit this group at http://groups.google.com/**
>> group/django-users?hl=en<http://groups.google.com/group/django-users?hl=en>
>> .
>>
>>
>

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