diff --git a/civicfix/core/models.py b/civicfix/core/models.py index 6e3ba7c..6a9f30e 100644 --- a/civicfix/core/models.py +++ b/civicfix/core/models.py @@ -1,7 +1,6 @@ -from django.db import models from django.contrib.auth.models import AbstractUser -from django.urls import reverse from django.core.validators import FileExtensionValidator +from django.db import models class User(AbstractUser): is_citizen = models.BooleanField(default=False) @@ -76,3 +75,20 @@ class Vote(models.Model): def __str__(self): return f"{self.user.username} voted on {self.issue.title}" + +class Comment(models.Model): + issue = models.ForeignKey(Issue, on_delete=models.CASCADE, related_name="comments") + user = models.ForeignKey(User, on_delete=models.CASCADE) + content = models.TextField() # <--- field name is "content", not "text" + parent = models.ForeignKey("self", null=True, blank=True, related_name="replies", on_delete=models.CASCADE) + created_at = models.DateTimeField(auto_now_add=True) + + class Meta: + ordering = ["created_at"] + + def __str__(self): + return f"Comment by {self.user} on {self.issue}" + + @property + def is_reply(self): + return self.parent is not None