On Sat, 2006-10-28 at 01:55 +0000, NakedHTML wrote: > I've been looking through the archives here and goggeling around trying > to resolve what I am sure is a simple problem. > > I am trying to do the following: > > 1) Display an article > 2) Display the reporter (many to many field) > 3) Display related images (many to many field) > > The model for the complete app is here: http://paste.e-scribe.com/2407/ > > I am trying to do in the template is this: > > {% for reporter in object.reporter_byline.all %} > {{ reporter.user.first_name }} > {% endfor %} > > This randomly breaks. Sometimes it does work and the username is > displayed and other times it'll break with > /Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/site-packages/Django-0.95-py2.4.egg/django/db/models/query.py > in lookup_inner, line 836
We may need a bit more information there. It sounds like (from the title of this email, which isn't mentioned anywhere else here) like one of the fields you are expecting to be non-null is empty and so the related instance doesn't exist and you can't query against it. However, it's very hard to tell. Your code paste is over 500 lines long, so I'm not going to be able to spot the error just by eye-balling it without devoting hours to the problem. If I were you, I would start by trying to trim down you failure to something as small as possible that fails. For example, which of the above two lines in your template is triggering the problem? If you remove the reporter.user.first_name line and replace it with a hard-coded string, do you still see the problem (which would indicate it is the first line)? You might also want to put the {% debug %} tag in your template and then view the resulting HTML source to see what the contents of your various objects are and whether they contain what you expect. Note that when using {% debug %}, it is important to "view source", because Python uses angle brackets for some of its output and this will be swallowed by the HTML rendering process which will throw away unknown elements. Using the debug output like this, you might be able to work out which particular value of "object" causes the problem and then inspect your database (and use "python manage.py shell") to do some investigations to see what results are really being returned. If none of this helps, reduce your template just to those two lines. Verifies that it still fails. Then start removing code from your models until things start working again. What was the last thing you removed? Why did it change things? Hope that gives you some clues to move forwards a little bit. 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users -~----------~----~----~----~------~----~------~--~---