mehdi-essebbar / bootcamp-hackernews

A web application for news, kind of a clone of this https://news.ycombinator.com/news, but for learning purposes.
0 stars 0 forks source link

use of `Topic.comment_count` #8

Closed hemache closed 6 years ago

hemache commented 6 years ago

why not rely on dynamic counting using Django ORM, something like

topic.comments.count()
mehdi-essebbar commented 6 years ago

I spoke about this issue with @dermoumi. He suggested that I use a property instead, which seams to work pretty fine.

hemache commented 6 years ago

yep, as long as we don't actually store the count in a database column. side question, why not return self.comment_set.count() instead of Comment.objects.filter(topic=self).count() ?

mehdi-essebbar commented 6 years ago

fixed, used the related_name=comments in the definition of the comment model and replaced Comment.objects.filter(topic=self).count() with self.comments.count()