OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

How to determine that the 'QuerySet' object does not have the 'comment' attribute in objects.filter(). Django [closed]

  • Thread starter Thread starter Дмитрий Морозов
  • Start date Start date
Д

Дмитрий Морозов

Guest
I am trying to display comments on the post page

Comments Models.py

Code:
from django.db import models
from product.models import Product

class Comment(models.Model):
    comment = models.TextField(name="comment")
    write = models.ForeignKey('product.Product', on_delete=models.CASCADE, null=True, blank=True, name="write")

Product Models.py

Code:
from django.db import models

class Product(models.Model):
    name = models.CharField(max_length=256, name="name")

Product View.py

Code:
def card(request, slug):
    product = Product.objects.get(id = slug)
    get_comments = Comment.objects.filter(write=product).distinct()
    print(get_comments.comment)
    context = {'product': product, 'comments': get_comments}
    return render(request, "product/card.html", context)

In get_comments.comment I get the error 'QuerySet' object has no attribute 'comment'
<p>I am trying to display comments on the post page</p>
<p>Comments Models.py</p>
<pre><code>from django.db import models
from product.models import Product

class Comment(models.Model):
comment = models.TextField(name="comment")
write = models.ForeignKey('product.Product', on_delete=models.CASCADE, null=True, blank=True, name="write")
</code></pre>
<p>Product Models.py</p>
<pre><code>from django.db import models

class Product(models.Model):
name = models.CharField(max_length=256, name="name")
</code></pre>
<p>Product View.py</p>
<pre><code>def card(request, slug):
product = Product.objects.get(id = slug)
get_comments = Comment.objects.filter(write=product).distinct()
print(get_comments.comment)
context = {'product': product, 'comments': get_comments}
return render(request, "product/card.html", context)
</code></pre>
<p>In get_comments.comment I get the error 'QuerySet' object has no attribute 'comment'</p>
 
Top