Thanks, I think I will have to do that, I just thought that there
might be an easy way to do this that I missed!

Paul Lundberg

On Sep 22, 11:56 am, Gonzalo Delgado <gonzalodelg...@fortix.com.ar>
wrote:
> El Mon, 21 Sep 2009 08:43:57 -0700 (PDT)
> Paul Lundberg <pfplundb...@gmail.com> escribió:
>
>
>
> > Hi:
> > I have several Django applications running and I am trying to tidu up
> > some code.
>
> > I am trying to make a generic way of viewing a database table on a web
> > page using a YUI control.
>
> > I am using the Django template to attempt to create the required
> > javascript for the YUI controls.
>
> > I become a bit stuck, in that I can't seem to iterate over the fields
> > in a record in a Django template.
>
> > For example I have a project table as follows:
>
> > class projects(models.Model):
> >     projectName                    = models.CharField('Project Name',
> > max_length=50, null=False)
> >     projectDescription     = models.TextField('Project Description',
> > null=True)
> >     projectManager         = models.CharField('Project Manager',
> > max_length=50, null=True)
> >     projectOwner           = models.CharField('Project Owner',
> > max_length=50, null=True)
> >     projectDate         = models.DateField('Project Date',
> > null=False)
> >     projectHidden          = models.BooleanField('Project Hidden',
> > null=True)
>
> > Then there is a Django view that is used to get the data to render, in
> > that I get a list of all the projects:
>
> >  projList = projects.objects.all()
>
> > projList is then passed into the function that renders the page.
>
> > I can go through each record in the projList using:
>
> > {% for projectItem in projList %}
> > :
> > :
> > {% endfor %}
>
> > However I can't seem to go through each field in an individual record
> > for example this doesn't work:
>
> > {% for projectItem in projList %}
> >     {% for fieldval in projectItem.fields %}
> >         {{fieldval.name }} -:-
> > {{ fiieldVal.str }}
> >     {% endfor %}
> > {% endfor %}
>
> > This doesn't cause an error but it doesn't produce any output.
>
> Model instances are not iterable (forms are, they're different type of 
> objects)
>
> > I can access the fields using the field names
>
> > {% for projectItem in projList %}
> >     {{ projList.projectName }}
> > :
> > {% endfor %}
>
> > This produces an output but this gets away from the point of making a
> > generic function..
>
> > Is this possible? Is this because the fields are not bound to a form's
> > fields?
>
> > Any help or advice would be greatly apprecriated!
>
> You could write a method that outputs what you want and call it from the
> template.
>
> --
> P.U. Gonzalo Delgado 
> <gonzalodelg...@fortix.com.ar>http://gonzalodelgado.com.ar/
>
>  application_pgp-signature_part
> < 1KViewDownload
--~--~---------~--~----~------------~-------~--~----~
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