I've tried a few things but i cannot get the correct date formats to 
calculate the difference, so far i have this: 

    popular_posts = Post.objects.extra(select={
    'popularity': '(' + datetime.datetime.now() + ' - created) * views'
    })

It shows an error, i've tried googling it but not had much luck so far

On Thursday, 16 August 2012 00:59:39 UTC+1, Melvyn Sopacua wrote:
>
> On 15-8-2012 23:01, Callum Bonnyman wrote: 
> > 
> > 
> > I am creating a popular page for my app and for the most part this is 
> just 
> > to gain an understanding. 
> > 
> > The idea is to divide the number of views by the days old, now i don't 
> know 
> > if this will be successful or even working but like I said its go get an 
> > idea of how queries work... 
> > 
> > My fields are named: views and created. Below is an idea of what I'm 
> > thinking of. 
> > 
> > (now - created) / views 
> You probably want views / (now - created) which means the average number 
> of views over time. Your function above calculates the average time 
> between views. 
>
> >     popular_posts = Post.objects.all().order_by('-id')[:50] 
>
> The problem isn't the calculation. The problem is that you want the 
> result of the calculation and the ability to sort with it. If you want 
> to keep this independent of the database backend I highly suggest you 
> calculate the value in python and store it in the database. 
>
> Otherwise, I don't see a way to avoid using the extra method: 
> <https://docs.djangoproject.com/en/1.4/ref/models/querysets/#extra> 
>
> -- 
> Melvyn Sopacua 
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/rrf6cN7n3oYJ.
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.

Reply via email to