So this is the first time you've explained the real problem you're trying to solve. It certainly helps explain, a little bit, at least, which direction to point you for solutions.
On Tue, 2009-03-10 at 02:28 -0700, NoviceSortOf wrote: > > It's clear now that __str__(self) or __unicode__ > return a usable string to the view. > > But this does not on the surface appear to be a > workable instance of the model itself, Right. If you want to access the model itself, pass the model to the template, not the output of __unicode__. The __unicode__ method returns a string (a Python unicode object). > that would return fields that I can work with in the template...and/or > i haven't figured how to get a handle on it. > > ie... > to list titles by Stevenson and checkbox titles to be borrowed. > ...which in the browser I'd hope would present something like > _______________________________________________________ > ... > [ ] Stevenson Collected Works > [ ] Stevenson Treasure Island > [ ] Stevenson Wild West Stories > ... > [Submit] Looking at Django's forms module would help you here. There are lots of classes and functions for creating HTML forms and converting models to forms. > > here is the code i'm trying... > ______________________________________________________ > # models.py > class Titles(models.Model): > > author = models.CharField(max_length=100) > > title = models.CharField(max_length=254) > > select = models.BooleanField() > > def __unicode__(self): > return u'%s = %s' % (self.author, self.title) > ________________________________________________________ > # views.py > def checkout_book_view(request) > from books.models import Titles > > titles_list =Titles.objects.filter(author="Stevenson") > > template_Name='checkoutbook.htm' > template_Context = Context( { 'titles_list': titles_list }) > > return render_to_response(template_Name,template_Context) > ________________________________________________________ > # then in template checkoutbook.html list as > {% for titles_list in titles_list %} > {{ title.select }} > {{ title.author }} > {{ title.title }} > {% endfor %} It looks like this should be working fine, printing out the values of each of those attributes. It sounds like you were hoping the BooleanField attribute would display as a checkbox, but it's not a form field. It's model field: so it holds data and can be used to access that data. If you want a checkbox, you'll need to create a form object (you could do that manually in HTML, but it's much easier to use django.forms). > > with unicode though all i'm able to get is the single string defined > by def ___unicode___ and no check box. i'm suprised > that the query set or list is not able to store more fields. What do you mean by "more fields"? The queryset returns a bunch of model instances and you can access everything in the model. What else are you after here? Have a read through all of the documentation under http://docs.djangoproject.com/en/dev/topics/forms/ and see if that helps you do what you're after. Regards, Malcolm --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---