Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Django QuerySet Not returning all data

I am trying to return all the data in queryset which is saved in my model. But when I try to print it only returns the title nothing else.

Bellow are the screenshots attached for refrence.

Please assist

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Code:
enter image description here

and here is the data which i have saved in my model

enter image description here

>Solution :

You will only see what you have used in str in models.py for the given instance



def __str__():
    return self.title + ' ' + '|' + ' ' + self.author


In your print message you only see ({'post':{title|author}}) that is returned from __str__

In your print message you will see the content that you have provided in str
but you can access other fields using below code,for example


post = Post.objects.filter(slug = slug)
print(post.read_time,post.hero_image, post.content)


I hope you got it.If not let me know.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading