Show More
@@ -0,0 +1,28 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 | def first_thread_to_thread(apps, schema_editor): | |
|
10 | Post = apps.get_model('boards', 'Post') | |
|
11 | for post in Post.objects.all(): | |
|
12 | post.thread = post.threads.first() | |
|
13 | post.save(update_fields=['thread']) | |
|
14 | ||
|
15 | ||
|
16 | dependencies = [ | |
|
17 | ('boards', '0008_auto_20150205_1304'), | |
|
18 | ] | |
|
19 | ||
|
20 | operations = [ | |
|
21 | migrations.AddField( | |
|
22 | model_name='post', | |
|
23 | name='thread', | |
|
24 | field=models.ForeignKey(related_name='pt+', to='boards.Thread', default=None, null=True), | |
|
25 | preserve_default=False, | |
|
26 | ), | |
|
27 | migrations.RunPython(first_thread_to_thread), | |
|
28 | ] |
@@ -91,6 +91,7 b' class PostManager(models.Manager):' | |||
|
91 | 91 | text=pre_text, |
|
92 | 92 | pub_time=posting_time, |
|
93 | 93 | poster_ip=ip, |
|
94 | thread=thread, | |
|
94 | 95 | poster_user_agent=UNKNOWN_UA, # TODO Get UA at |
|
95 | 96 | # last! |
|
96 | 97 | last_edit_time=posting_time) |
@@ -151,9 +152,12 b' class PostManager(models.Manager):' | |||
|
151 | 152 | referenced_post.build_refmap() |
|
152 | 153 | referenced_post.save(update_fields=['refmap', 'last_edit_time']) |
|
153 | 154 | |
|
154 | referenced_thread = referenced_post.get_thread() | |
|
155 |
|
|
|
156 | referenced_thread.save(update_fields=['last_edit_time']) | |
|
155 | referenced_threads = referenced_post.get_threads().all() | |
|
156 | for thread in referenced_threads: | |
|
157 | thread.last_edit_time = post.pub_time | |
|
158 | thread.save(update_fields=['last_edit_time']) | |
|
159 | ||
|
160 | post.threads.add(thread) | |
|
157 | 161 | |
|
158 | 162 | @cached_result |
|
159 | 163 | def get_posts_per_day(self): |
@@ -220,6 +224,7 b' class Post(models.Model, Viewable):' | |||
|
220 | 224 | db_index=True) |
|
221 | 225 | refmap = models.TextField(null=True, blank=True) |
|
222 | 226 | threads = models.ManyToManyField('Thread', db_index=True) |
|
227 | thread = models.ForeignKey('Thread', db_index=True, related_name='pt+') | |
|
223 | 228 | |
|
224 | 229 | def __str__(self): |
|
225 | 230 | return 'P#{}/{}'.format(self.id, self.title) |
@@ -299,9 +304,8 b' class Post(models.Model, Viewable):' | |||
|
299 | 304 | |
|
300 | 305 | return link |
|
301 | 306 | |
|
302 | # TODO This must be removed after full transition to multiple threads | |
|
303 | 307 | def get_thread(self): |
|
304 |
return self. |
|
|
308 | return self.thread | |
|
305 | 309 | |
|
306 | 310 | def get_threads(self): |
|
307 | 311 | """ |
General Comments 0
You need to be logged in to leave comments.
Login now