From 22330e6d9f1fad8319e02d8ecef3c5068f02e462 Mon Sep 17 00:00:00 2001 From: Skia Date: Wed, 31 May 2017 19:50:41 +0200 Subject: [PATCH] forum: add on_delete=models.SET_NULL on _last_message fields Signed-off-by: Skia --- ...70530_2058.py => 0004_auto_20170531_1949.py} | 17 +++++++++-------- forum/models.py | 6 ++++-- 2 files changed, 13 insertions(+), 10 deletions(-) rename forum/migrations/{0004_auto_20170530_2058.py => 0004_auto_20170531_1949.py} (60%) diff --git a/forum/migrations/0004_auto_20170530_2058.py b/forum/migrations/0004_auto_20170531_1949.py similarity index 60% rename from forum/migrations/0004_auto_20170530_2058.py rename to forum/migrations/0004_auto_20170531_1949.py index d236d5ac..0ae64560 100644 --- a/forum/migrations/0004_auto_20170530_2058.py +++ b/forum/migrations/0004_auto_20170531_1949.py @@ -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), ), ] diff --git a/forum/models.py b/forum/models.py index 9f0f76e5..b7f0c8d8 100644 --- a/forum/models.py +++ b/forum/models.py @@ -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)