How can I get the rows from the PostgreSQL with specific value?
I have this table with columns: id | accountid | dictdata | date |
Inside the dictdata column contains a bunch of dictionary data.
in my models.py
class charts(models.Model):
id = models.AutoField(primary_key=True)
accoundid= models.IntegerField(default=None,blank=True)
dictdata= models.JSONField(default=None,null=True, blank=True)
date = models.DateTimeField(auto_now=True)
class Meta:
db_table = "charts"
in my python file
data = list(charts.objects.values('dictdata ')) //all dictionary data
print(data)
Example of print(data):
[{'dictdata': {'select': 'bar', 'title': 'some title'}},
{'dictdata': {'select': 'line', 'title': 'some title'}},
{'dictdata': {'select': 'pie', 'title': 'some title'}}]
how can I get the rows that contains a specific ‘select’ value? for example I want to get all the rows with ‘bar’
{'dictdata': {'select': 'bar', 'title': 'some title'}}
2
Answers
You can get the rows from the PostgreSQL with specific value.
If the data inside
dictdata
is adict
and is not alist
, you can filter like this: