DjangoGirls / tutorial-extensions

Additional tasks for tutorial
https://tutorial-extensions.djangogirls.org
Other
163 stars 203 forks source link

comments count #39

Closed jssidhu94 closed 8 years ago

jssidhu94 commented 8 years ago

comments count on post_list page is not working. When changing it to show only count of approved comments on post_list page it shows "Comments: ".

CatherineWeird commented 8 years ago

in the line <a href="{% url 'blog.views.post_detail' pk=post.pk %}">Comments: {{ post.comments.count }}</a> in blog/post_list.html make sure it reads post.comments.count and not post.comment.count

Also if you are seeing the Speech marks around the word Comments check you have those in the right places.

I had the same problems.

jssidhu94 commented 8 years ago

But it is displaying all comments but not approved ones.

On Sat, Apr 23, 2016 at 6:32 PM, Catherine Jones notifications@github.com wrote:

in the line Comments: {{ post.comments.count }} in blog/post_list.html make sure it reads post.comments.count and not post.comment.count

Also if you are seeing the Speech marks around the word Comments check you have those in the right places.

I had the same problems.

— You are receiving this because you are subscribed to this thread. Reply to this email directly or view it on GitHub https://github.com/DjangoGirls/tutorial-extensions/issues/39#issuecomment-213737114

Regards

Jagdeep Singh

VdeJong commented 8 years ago

@PIEBY4 change post.comments.count to post.approved_comments.count and make sure you have the approved comments method added to the post model in blog/models.py

helenst commented 8 years ago

I'm going to close this as I don't think there's anything incorrect in the tutorial here. @PIEBY4 I hope you managed to get this working! :)

drfelipex commented 7 years ago

Go Models add in class Post def approved_comments(self): return self.comments.filter(approved_comment=True)


class Post(models.Model): author = models.ForeignKey('auth.User') title = models.CharField(max_length=200) text = models.TextField() created_date = models.DateTimeField( default=timezone.now) published_date = models.DateTimeField( blank=True, null=True)

def publish(self):
    self.published_date = timezone.now()
    self.save()

def __str__(self):
    return self.title

# approved_comments(self) para contador de comentarios funcionar !!
def approved_comments(self):
    return self.comments.filter(approved_comment=True)
steveshead commented 7 years ago

@drfelipex - thank you - this worked for me - I knew it was something simple. The tutorial didn't mention adding to the Post class, but does have it added to the Comment class!

nnkps commented 7 years ago

Not true, at the end of the tutorial it is clearly written:

Finally, add this method to the Post model in blog/models.py:

def approved_comments(self):
    return self.comments.filter(approved_comment=True)
steveshead commented 7 years ago

Oh gosh - I totally got that wrong - sorry 'bout that! Guess I need to put the computer down for a while! 😜

Thanks for clarifying.

Steve

On Jul 9, 2017, at 1:16 AM, Anna Kupś notifications@github.com wrote:

Not true, at the end of the tutorial it is clearly written:

Finally, add this method to the Post model in blog/models.py:

def approved_comments(self): return self.comments.filter(approved_comment=True) — You are receiving this because you commented. Reply to this email directly, view it on GitHub, or mute the thread.