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:
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.