[reference: http://www.djangosnippets.org/snippets/82 ]

Tipan,

>From your code I think you may be confusing a dictionary
key with a list index.

> data_list=UserPoints.objects.filter(user = myuser)
> for i in data_list:
>     k='type_%d' % i
>     l='points_%d' % i

Note in line #28 how I'm defining a range of
integers.  Your range would be something like

  for i in range(1, len(data_list)+1):

> I note that you've defined the size of your
> dictionary using in the Form class using:

> number_of_meds = kwargs.pop('number_of_meds', 4)

The number_of_meds has been defined as an
arbitrary minimum of 4.  When you say "size
of your dictionary", this is actually the
number of med fields, or length of self.med_list.
In other words, in this example I wanted to display
a mininum of 4 medication fields, regardless of how
many meds were present.  The example displays 2 meds
and 2 blank medication fields.

> Please can you advise:
> The best way to pass my queryset data to the Form class
> How to pass the number of records to the Form class

The best way is to probably put all the queryset
code within __init__ of your form class.  Or call
an external function within __init__ that returns
the values you need to assemble them in the form.

--
Jeff Bauer
Rubicon, Inc.


--~--~---------~--~----~------------~-------~--~----~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to