Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add related name to Comments.author #127

Merged
merged 3 commits into from
Sep 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions todo/migrations/0012_add_related_name_to_comments.py
Original file line number Diff line number Diff line change
@@ -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_add_related_name_to_created_by'),
]

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),
),
]
3 changes: 2 additions & 1 deletion todo/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would think this change would break todo code in at least one place, no? Will test soon. But the system still works for you?

Copy link
Contributor Author

@bernd-wechner bernd-wechner Sep 28, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All existing tests passed. The code is running live and in use. And there are no references to comment_set, the default related_name anywhere in the code base. Looks safe to me.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent, thank you for looking.

)
task = models.ForeignKey(Task, on_delete=models.CASCADE)
date = models.DateTimeField(default=datetime.datetime.now)
Expand Down