H
H
Hideo0022021-06-23 13:45:23
Django
Hideo002, 2021-06-23 13:45:23

How to add list to db using django?

I need that when clicking on a button in HTML, a process would be performed that would automatically take the created list (list) of the ping and fill, directly, the ping and the hostname into the database table through django.

The list itself.

from pythonping import ping


def pingchecker():
    Response_List = ping('google.com', timeout=60, count=60, interval=1, verbose=True, df=True)
    return Response_List._responses                       #Сам список


The database itself is MySQL

Please explain how to do this.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim, 2021-06-23
@Tomio

If you use the Dzhang ORM, then everything is done through the model. You create, for example, a PingResult model, in which there will be a ping_list field with the JSON type, and then save the json with the list there.
If there was a PostgreSQL database, then you can create fields with the Array type in it - just for lists.
If ORM is not used and you need to put data into a ready-made database, into a specific table and field, then use a "raw" query:

from django.db import connection
with connection.cursor() as cursor:
    cursor.execute('INSERT INTO sometable (somefield) VALUES (ping_list)');

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question