How to enter all model-related data on one form?

2006-03-12 Thread Mike Kent

I want to create a form for entering data and all of its related data,
on one form.  Here's a simplified model to illustrate:

class Author(meta.Model):
name = meta.CharField(maxlength=40)

class Book(meta.Model):
title = meta.CharField(maxlength=40)
authors = meta.ManyToManyField(Author)

What I want to do is create a form that lets me enter the book title,
and a comma-separated list of author names.  The list of author names
would then be split on the commas, and if an author name was not in the
Author table, it would be inserted.  I want the form to work for both
create and update.

Can someone give me a pointer to info on how to go about this?


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



Can I pass a python iterator to a template?

2006-03-09 Thread Mike Kent

I want to display a grid view of some of the data from a large
database.  I want to manipulate each data row prior to displaying it,
so I can't just let the template code do the database read work.  Since
the dataset is potentially large, what I want to do is write an
iterator which will read the model's data (using get_iterator()',
manipulate the data rows, and then yield a dictionary (what Django
seems to call a 'context') for each row.  Then I would pass my iterator
in to the template, and use a 'for' loop in the template to get each
row of the data and fill in the data values.

When I actually try this, I get a traceback ending with:

/home/mike/Work/projects/django/trunk/django/core/template/defaulttags.py
in render

  83. context.push()
  84. try:
  85. values = self.sequence.resolve(context)
  86. except VariableDoesNotExist:
  87. values = []
  88. if values is None:
  89. values = []

  90. len_values = len(values)

So, am I completely off base here?  Is what I want to do not possible,
or is there another way I can tackle this?

Thanks,
Mike Kent


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