forum: add on_delete=models.SET_NULL on _last_message fields

Signed-off-by: Skia <skia@libskia.so>
This commit is contained in:
Skia 2017-05-31 19:50:41 +02:00
parent e5ce9658ee
commit 22330e6d9f
2 changed files with 13 additions and 10 deletions

View File

@ -2,6 +2,7 @@
from __future__ import unicode_literals
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
@ -22,41 +23,41 @@ class Migration(migrations.Migration):
migrations.AddField(
model_name='forum',
name='_last_message',
field=models.ForeignKey(related_name='forums_where_its_last', null=True, to='forum.ForumMessage', verbose_name='the last message'),
field=models.ForeignKey(verbose_name='the last message', to='forum.ForumMessage', null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='forums_where_its_last'),
),
migrations.AddField(
model_name='forum',
name='_topic_number',
field=models.IntegerField(verbose_name='number of topics', default=0),
field=models.IntegerField(default=0, verbose_name='number of topics'),
),
migrations.AddField(
model_name='forummessage',
name='_deleted',
field=models.BooleanField(verbose_name='is deleted', default=False),
field=models.BooleanField(default=False, verbose_name='is deleted'),
),
migrations.AddField(
model_name='forumtopic',
name='_last_message',
field=models.ForeignKey(related_name='+', null=True, to='forum.ForumMessage', verbose_name='the last message'),
field=models.ForeignKey(verbose_name='the last message', to='forum.ForumMessage', null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='+'),
),
migrations.AddField(
model_name='forumtopic',
name='_message_number',
field=models.IntegerField(verbose_name='number of messages', default=0),
field=models.IntegerField(default=0, verbose_name='number of messages'),
),
migrations.AddField(
model_name='forumtopic',
name='_title',
field=models.CharField(max_length=64, verbose_name='title', blank=True),
field=models.CharField(max_length=64, blank=True, verbose_name='title'),
),
migrations.AlterField(
model_name='forum',
name='description',
field=models.CharField(max_length=512, verbose_name='description', default=''),
field=models.CharField(max_length=512, default='', verbose_name='description'),
),
migrations.AlterField(
model_name='forum',
name='id',
field=models.AutoField(serialize=False, db_index=True, primary_key=True),
field=models.AutoField(primary_key=True, serialize=False, db_index=True),
),
]

View File

@ -58,7 +58,8 @@ class Forum(models.Model):
view_groups = models.ManyToManyField(Group, related_name="viewable_forums", blank=True,
default=[settings.SITH_GROUP_PUBLIC_ID])
number = models.IntegerField(_("number to choose a specific forum ordering"), default=1)
_last_message = models.ForeignKey('ForumMessage', related_name="forums_where_its_last", verbose_name=_("the last message"), null=True)
_last_message = models.ForeignKey('ForumMessage', related_name="forums_where_its_last",
verbose_name=_("the last message"), null=True, on_delete=models.SET_NULL)
_topic_number = models.IntegerField(_("number of topics"), default=0)
class Meta:
@ -181,7 +182,8 @@ class ForumTopic(models.Model):
forum = models.ForeignKey(Forum, related_name='topics')
author = models.ForeignKey(User, related_name='forum_topics')
description = models.CharField(_('description'), max_length=256, default="")
_last_message = models.ForeignKey('ForumMessage', related_name="+", verbose_name=_("the last message"), null=True)
_last_message = models.ForeignKey('ForumMessage', related_name="+", verbose_name=_("the last message"),
null=True, on_delete=models.SET_NULL)
_title = models.CharField(_('title'), max_length=64, blank=True)
_message_number = models.IntegerField(_("number of messages"), default=0)