Hi! wondering if someone could point me in the right direction with this one:
I'm trying to populate fields in a form with data from database: i.e. suppose I've this model: -- models.py -- class Book(models.Model): title = models.CharField(max_length=100) pages = models.IntegerField() author = models.ForeignKey(Author) price = models.DecimalField(max_digits=5, decimal_places=2) I create a form with all books and checkbox for each one that let's the user select one or more book and calculate a total price. If I’ve understood correctly I need a forms.py like the following to generate <checkbox> with differents "id" -- forms.py -- class BookForm(forms.Form): def __init__(self, *args, **kwargs): super(BookForm, self).__init__(*args, **kwargs) books = Book.objects.all() for item in books: fieldname = '%s' % item.pk self.fields[fieldname] = forms.BooleanField (required=False) Finally, this is the problem: How I can get book info like "title", "price" etc. and show their in the template? (This is the template, it doesn't work but it reflects what I'd like) <form action="." method="POST"> {% for field in form %} Book title: {{how I can get the title?}} - Price {{how I can get the price?} - select it: {{field}} <br/> {% endfor %} <br> <input type="submit" value="Calculate" /> </form> --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---