Re: Odd problem with queryset

2011-04-05 Thread bruno desthuilliers
On 4 avr, 17:44, Adam Tonks wrote: > On Monday, April 4, 2011 4:34:10 PM UTC+1, bruno desthuilliers wrote: > > > If you really did test on the very same data set, same forum, *same > > thread* (IOW ; same value for "self.pk") etc, you would'nt get an > > IndexError, so there's obviously something

Re: Odd problem with queryset

2011-04-04 Thread Adam Tonks
On Monday, April 4, 2011 4:34:10 PM UTC+1, bruno desthuilliers wrote: > > If you really did test on the very same data set, same forum, *same > thread* (IOW ; same value for "self.pk") etc, you would'nt get an > IndexError, so there's obviously something different. > I was literally just adding

Re: Odd problem with queryset

2011-04-04 Thread bruno desthuilliers
On 3 avr, 23:12, Adam Tonks wrote: > I have a function in a model to return the first post in a forum thread.  At > the moment, it looks like this: > > return Post.objects.filter(thread = self.pk).order_by('created') > > When I run it in my test forum, the code returns two posts: > > [, reply to

Re: Odd problem with queryset

2011-04-04 Thread Dmitry Kharlamov
Sorry, meant None instead of NULL — crazy past week with lots of JS in my life! On Apr 4, 1:35 am, Adam Tonks wrote: > At the suggestion of someone on IRC, I tried accessing the first result from > within my template, using {{ thread.original_author.0 }} (where > original_author is the name of th

Re: Odd problem with queryset

2011-04-04 Thread Dmitry Kharlamov
Try to instead limit the QuerySet: try: post = Post.objects.filter(thread = self.pk).order_by('created')[: 1].get() except DoesNotExist: post = NULL return post # or do something else http://docs.djangoproject.com/en/1.3/topics/db/queries/#limiting-querysets On Apr 4, 1:35 am, Adam Tonk

Re: Odd problem with queryset

2011-04-03 Thread Adam Tonks
At the suggestion of someone on IRC, I tried accessing the first result from within my template, using {{ thread.original_author.0 }} (where original_author is the name of the function with the return statement), and that works fine. It's a workaround, but not ideal, as I'll be using it in vari

Odd problem with queryset

2011-04-03 Thread Adam Tonks
I have a function in a model to return the first post in a forum thread. At the moment, it looks like this: return Post.objects.filter(thread = self.pk).order_by('created') When I run it in my test forum, the code returns two posts: [, ] I then add a [0] to the end of the statement, to just r