##// END OF EJS Templates
Don't include archived posts into the random image list
neko259 -
r1250:4c8a70f6 default
parent child Browse files
Show More
@@ -0,0 +1,19 b''
1 # -*- coding: utf-8 -*-
2 from __future__ import unicode_literals
3
4 from django.db import models, migrations
5
6
7 class Migration(migrations.Migration):
8
9 dependencies = [
10 ('boards', '0019_auto_20150519_1323'),
11 ]
12
13 operations = [
14 migrations.AlterField(
15 model_name='post',
16 name='images',
17 field=models.ManyToManyField(to='boards.PostImage', blank=True, null=True, db_index=True, related_name='post_images'),
18 ),
19 ]
@@ -42,8 +42,9 b' class PostImageManager(models.Manager):'
42 42 md5.update(chunk)
43 43 return md5.hexdigest()
44 44
45 def get_random_images(self, count):
46 return self.order_by('?')[:count]
45 def get_random_images(self, count, include_archived=False):
46 return self.filter(post_images__thread__archived=include_archived)\
47 .order_by('?')[:count]
47 48
48 49
49 50 class PostImage(models.Model, Viewable):
@@ -168,7 +168,7 b' class Post(models.Model, Viewable):'
168 168 _text_rendered = TextField(blank=True, null=True, editable=False)
169 169
170 170 images = models.ManyToManyField(PostImage, null=True, blank=True,
171 related_name='ip+', db_index=True)
171 related_name='post_images', db_index=True)
172 172
173 173 poster_ip = models.GenericIPAddressField()
174 174
General Comments 0
You need to be logged in to leave comments. Login now