From dff907e6d71110208de223ef7e8861a98ae0312c Mon Sep 17 00:00:00 2001 From: Bernd Wechner Date: Wed, 22 Sep 2021 16:30:06 +1000 Subject: [PATCH 1/3] Add related name to Comments.author --- todo/models.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/todo/models.py b/todo/models.py index c79d3dc..17355a1 100644 --- a/todo/models.py +++ b/todo/models.py @@ -133,7 +133,8 @@ class Comment(models.Model): """ author = models.ForeignKey( - settings.AUTH_USER_MODEL, on_delete=models.CASCADE, blank=True, null=True + settings.AUTH_USER_MODEL, on_delete=models.CASCADE, blank=True, null=True, + related_name="todo_comments" ) task = models.ForeignKey(Task, on_delete=models.CASCADE) date = models.DateTimeField(default=datetime.datetime.now) From fe103a5441264284d75b3d2456d018e449ed0b2a Mon Sep 17 00:00:00 2001 From: Bernd Wechner Date: Thu, 23 Sep 2021 21:00:50 +1000 Subject: [PATCH 2/3] Migration to support comment fix --- todo/migrations/0012_auto_20210922_2205.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 todo/migrations/0012_auto_20210922_2205.py diff --git a/todo/migrations/0012_auto_20210922_2205.py b/todo/migrations/0012_auto_20210922_2205.py new file mode 100644 index 0000000..f92eeba --- /dev/null +++ b/todo/migrations/0012_auto_20210922_2205.py @@ -0,0 +1,20 @@ +# Generated by Django 2.2.24 on 2021-09-22 22:05 + +from django.conf import settings +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('todo', '0011_auto_20190724_1130'), + ] + + operations = [ + migrations.AlterField( + model_name='comment', + name='author', + field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='todo_comments', to=settings.AUTH_USER_MODEL), + ), + ] From 894ca22f9a792ff49a9244acaf41cdf02bf73001 Mon Sep 17 00:00:00 2001 From: Bernd Wechner Date: Wed, 29 Sep 2021 09:59:22 +1000 Subject: [PATCH 3/3] Naming migrations sensibly --- ..._20190724_1130.py => 0011_add_related_name_to_created_by.py} | 0 ...to_20210922_2205.py => 0012_add_related_name_to_comments.py} | 2 +- 2 files changed, 1 insertion(+), 1 deletion(-) rename todo/migrations/{0011_auto_20190724_1130.py => 0011_add_related_name_to_created_by.py} (100%) rename todo/migrations/{0012_auto_20210922_2205.py => 0012_add_related_name_to_comments.py} (90%) diff --git a/todo/migrations/0011_auto_20190724_1130.py b/todo/migrations/0011_add_related_name_to_created_by.py similarity index 100% rename from todo/migrations/0011_auto_20190724_1130.py rename to todo/migrations/0011_add_related_name_to_created_by.py diff --git a/todo/migrations/0012_auto_20210922_2205.py b/todo/migrations/0012_add_related_name_to_comments.py similarity index 90% rename from todo/migrations/0012_auto_20210922_2205.py rename to todo/migrations/0012_add_related_name_to_comments.py index f92eeba..b10dd19 100644 --- a/todo/migrations/0012_auto_20210922_2205.py +++ b/todo/migrations/0012_add_related_name_to_comments.py @@ -8,7 +8,7 @@ class Migration(migrations.Migration): dependencies = [ - ('todo', '0011_auto_20190724_1130'), + ('todo', '0011_add_related_name_to_created_by'), ] operations = [