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
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
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
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
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
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
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
7 matches
Mail list logo