Thanks.   I've set extra=0 and added an element to the list, and
now the last form on the page is half-initialized - the date is set
but the time is not!
What could cause that??

On May 26, 9:20 pm, Sam Chuparkoff <s...@sadach.org> wrote:
> On Tue, 2009-05-26 at 17:27 -0700, adrian wrote:
> > This code creates a formset and populates fields with copies of
> > date and start_time.
> > The problem is, if num_events is X then it creates X forms but it only
> > populates X-1   (it leaves the last one uninitialized).   My question
> > is why, and how to fix it? Thanks.
>
> >        DateTimeFormSet = formset_factory(DateTimeForm)
> >         initial_data_list = []
> >         pattern_datetime_dict = {
> >             'date':event.date,
> >             'start_time':event.time_start,
> >         }
>
> >         for x in range(1, num_events):
> >             initial_data_list.append(pattern_datetime_dict)
>
> >         formset = DateTimeFormSet(initial = initial_data_list)
>
> Your initial data list only has (num_events - 1) elements. And
> formset_factory is returning a formset class that generates 1 extra
> form by default, giving you num_events total forms.
>
> If you don't want any extra forms, you can pass extra=0 into
> formset_factory like so:
>
>   DateTimeFormSet = formset_factory(DateTimeForm, extra=0)
>
> sdc
--~--~---------~--~----~------------~-------~--~----~
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