fix: Show name of reported content

This commit is contained in:
2025-03-10 22:03:47 +01:00
parent 3607eb0e4e
commit 9086e2e75b
3 changed files with 22 additions and 5 deletions

View File

@@ -680,6 +680,21 @@ class Report(models.Model):
def get_moderation_actions(self):
return ModerationAction.objects.filter(report=self)
@property
def reported_content(self):
"""
Dynamically fetch the reported content based on subclass.
The alternative would be to use the ContentType framework:
https://docs.djangoproject.com/en/5.1/ref/contrib/contenttypes/
"""
print("dodo")
if hasattr(self, "reportadoptionnotice"):
return self.reportadoptionnotice.adoption_notice
elif hasattr(self, "reportcomment"):
return self.reportcomment.reported_comment
print("dada")
return "didi"
class ReportAdoptionNotice(Report):
adoption_notice = models.ForeignKey("AdoptionNotice", on_delete=models.CASCADE)
@@ -688,6 +703,9 @@ class ReportAdoptionNotice(Report):
def reported_content(self):
return self.adoption_notice
def __str__(self):
return f"Report der Vermittlung {self.adoption_notice}"
class ReportComment(Report):
reported_comment = models.ForeignKey("Comment", on_delete=models.CASCADE)