random.py
28 lines
| 665 B
| text/x-python
|
PythonLexer
|
r1246 | from django.shortcuts import render | ||
from django.template import RequestContext | ||||
from django.views.generic import View | ||||
from django.db.models import Count | ||||
from boards.models import Post | ||||
from boards.mdx_neboard import Parser | ||||
__author__ = 'neko259' | ||||
TEMPLATE = 'boards/random.html' | ||||
CONTEXT_POSTS = 'posts' | ||||
RANDOM_POST_COUNT = 10 | ||||
class RandomImageView(View): | ||||
def get(self, request): | ||||
params = dict() | ||||
posts = Post.objects.annotate(images_count=Count( | ||||
'images')).filter(images_count__gt=0).order_by('?')\ | ||||
[:RANDOM_POST_COUNT] | ||||
params[CONTEXT_POSTS] = posts | ||||
return render(request, TEMPLATE, params) | ||||