3

I'm working on HStoreField in Django. I can able to store the data in HstoreField(). but i dont know how to retrive data from hstore filed

models.py

class myhstore(models.Model):
file_name= models.CharField(max_length = 20)
content = HStoreField()

I am storing data as

file_name = "Sample.csv"

content

{'Name':'A','Age':'21','Place':'AAA'}

{'Name':'B','Age':'20','Place':'BBB'}

{'Name':'C','Age':'21','Place':'CCC'}

{'Name':'D','Age':'20','Place':'AAA'}

{'Name':'E','Age':'21','Place':'CCC'}

{'Name':'F','Age':'22','Place':'AAA'}

and in Postgre table it is storing as

"Name"=>"A", "Age"=>"21", "Place"=>"AAA"
"Name"=>"B", "Age"=>"20", "Place"=>"BBB"
"Name"=>"C", "Age"=>"21", "Place"=>"CCC"
"Name"=>"D", "Age"=>"20", "Place"=>"AAA"
"Name"=>"E", "Age"=>"21", "Place"=>"CCC"
"Name"=>"F", "Age"=>"22", "Place"=>"AAA"

Here , i need to query from table using python as

if selecting "Place" need Values in Place and their count like

AAA - count- 3 BBB - count- 1 CCC - count- 2

if selecting "Place" and "Age"

AAA,21 - count - 1

AAA,20 - count - 1

AAA,22 - count - 1

BBB,20 - count - 1

CCC,21 - count - 2

Please help me to do this..

Thanks in Advance..

Arjun
  • 31
  • 6

0 Answers0