JSON file

30 views
Skip to first unread message

HJ

unread,
May 22, 2020, 1:48:36 PM5/22/20
to Django users
hello django users hope you are doing well 

I want to do a highchart using a json file , and that's the problem I am facing , I want to create a json file in my views.py based on my columns below "countDeliveries"and "Dates"

class mail_item_count_deliveries_perDate(models.Model):
   countDeliveries = models.IntegerField(default=0)
   Dates = models.DateTimeField()


myJSON file should be something like that:
 
[
        [
                Dates,
                countDeliveries
        ],
        [
                1167696000000,
                5
        ],

 
- can you guys help me out 

Vishesh Mangla

unread,
May 22, 2020, 2:26:28 PM5/22/20
to django...@googlegroups.com

I ‘m not sure if that is a JSON file because a JSON file is nothing but a python dictionary like structure and that doesn’t seem to be that. Anyways you can see python’s building json module’s json.dumps() function.

 

Sent from Mail for Windows 10

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/65341e88-88b1-480f-9d9a-39ce909ee4da%40googlegroups.com.

 

Derek

unread,
May 25, 2020, 2:27:10 AM5/25/20
to Django users
I am not sure about the field names part, but you could probably create that manually very easily.

For the data section, you need a list of lists, which you can get from code like:

import json
data_ready_for_json = list(mail_item_count_deliveries_perDate.objects.values_list('countDeliveries','Dates'))
json_string = json.dumps(data_ready_for_json)

(P.S. you may want to consider giving your classes more Python-like names e.g. class MailDelivery )
Reply all
Reply to author
Forward
0 new messages