More article features and markdown editor

How to add custom computed properties to our models

Want more?

This lesson for enrolled students only. Join the course to unlock it!

You can see the code changes implemented in this lecture below.

If you have purchased the course in a different platform, you still have access to the code changes per lecture here on Teclado. The lecture video and lecture notes remain locked.
Join course for $15

Modified files

app/models.py
--- 
+++ 
@@ -21,6 +21,14 @@

     USERNAME_FIELD = "email"
     REQUIRED_FIELDS = []
+
+    @property
+    def article_count(self):
+        return self.articles.count()
+    
+    @property
+    def written_words(self):
+        return self.articles.aggregate(models.Sum("word_count"))["word_count__sum"] or 0


 class Article(models.Model):