if your title object has a __str__ then it can be printed.
Printing a queryset object make no sense!
HTH
Etienne
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/9d47f644-68f6-4939-a0f2-65b4681701b5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
-- Etienne Robillard tka...@yandex.com https://www.isotopesoftware.ca/
get_object = get_object_or_404(Title, title=title)
if get_object:
print(get_object.title)
or
title = Title.objects.filter(title=title)
if title:
print(title[0].title)
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
class Comment(models.Model):
comment_title = models.TextField()
comment_content = models.TextField()
def __str__(self):
return self.comment_content
def test_me():
comment_id_set = list(Comment.objects.values_list('id', flat=True))
for pk in comment_id_set:
comment = Comment.objects.filter(pk=pk)
print(comment)
Here's the snippet of my code:models.py:class Comment(models.Model):
comment_title = models.TextField()
comment_content = models.TextField()
def __str__(self):
return self.comment_contentdef test_me():
comment_id_set = list(Comment.objects.values_list('id', flat=True))
for pk in comment_id_set:
comment = Comment.objects.filter(pk=pk)
print(comment)Output:<QuerySet [<Comment: Nice weather and location. Not much food choices. The room was fair but clean. Not really fancy. The staff was friendly and helpful. :)>]><QuerySet [<Comment: I booked this room for my brother as a gift. They really enjoyed the place.>]>