added Comment model

This commit is contained in:
2025-08-22 06:57:16 +05:30
parent 8d8c559778
commit a331e81292
+18 -2
View File
@@ -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