Log in

Get the likes count for first comment

  • 29 Apr '16

Is it possible to get the likes count for just the first comment. I want to be able to add to the list, the likes count of the actual question itself. Thank you!

nitelyEsteban Castro Borsani
  • 3
  • 29 Apr '16

Likes are per comment not per topic, so no, there is no way.

There are a couple of ways to achieve this. The most straightforward way is to create a OneToOneField in the topic model (or an extension of it) related to the comment model and then save that relationship when creating a topic. You have to save the topic, then save the comment, then update that topic field (so it has to be nullable).

Another way is to pre-fetch all first comment for every topic, I always forget how to do this though, so check the django docs. But I'm unsure it's possible to limit to just 1 comment (ie: the first one), I don't think so