Modified files
app/models.py
---
+++
@@ -1,3 +1,4 @@
+import re
from django.db import models
from django.contrib.auth.models import AbstractUser
@@ -23,4 +24,9 @@
default="draft",
)
created_at = models.DateTimeField(auto_now_add=True)
- updated_at = models.DateTimeField(auto_now=True)+ updated_at = models.DateTimeField(auto_now=True)
+
+ def save(self, *args, **kwargs):
+ text = re.sub(r"<[^>]*>", "", self.content).replace(" ", " ")
+ self.word_count = len(re.findall(r"\b\w+\b", text))
+ super().save(*args, **kwargs)