##// END OF EJS Templates
Store user settings apart from session in the database
Store user settings apart from session in the database

File last commit:

r1986:0b41439a default
r2041:c2c571fa default
Show More
0014_auto_20150418_1749.py
33 lines | 1000 B | text/x-python | PythonLexer
/ boards / migrations / 0014_auto_20150418_1749.py
neko259
Store each post URL in the database instead of computing it every time
r1112 # -*- coding: utf-8 -*-
from __future__ import unicode_literals
neko259
Adapt to django-2.0
r1986 from django.urls import reverse
neko259
Store each post URL in the database instead of computing it every time
r1112
from django.db import models, migrations
class Migration(migrations.Migration):
def update_urls(apps, schema_editor):
Post = apps.get_model('boards', 'Post')
for post in Post.objects.all():
thread = post.thread
opening_id = Post.objects.filter(threads__in=[thread]).order_by('pub_time').first().id
post_url = reverse('thread', kwargs={'post_id': opening_id})
if post.id != opening_id:
post_url += '#' + str(post.id)
post.url = post_url
post.save(update_fields=['url'])
dependencies = [
('boards', '0013_auto_20150408_1210'),
]
operations = [
migrations.AddField(
model_name='post',
name='url',
field=models.TextField(default=''),
preserve_default=False,
),
migrations.RunPython(update_urls),
]