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

Accessing model data in django

I have a a Django model:

class Myvalues(models.Model):
        items_list = models.JSONField()

I have populated this model in Django admin. I now want to access the data inside this model. However I am getting an error that says: 'Manager' object has no attribute ‘items_list'
The way I am trying to access it is as follows:

Print(Myvalues.objects.items_list.values())

I don’t understand why this is coming up as the class has that model in it.
Out of interest I printed the all() result of Myvalues class, like so:

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

print(Myvalues.objects.all())

this resulted in the following:

<QuerySet [<Myvalues: Myvalues object (1)>]>

How can I access the data that’s in my items_list model?

>Solution :

Use the following syntax instead (documentation).

Myvalues.objects.values_list('items_list', flat=True)

If you want to have tuples returned, omit flat=True.

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