I
I
Injustive2021-06-23 14:01:51
Django
Injustive, 2021-06-23 14:01:51

How to import data into django model?

I have a database. 60d3136abf0d5041521206.png
I need to import data into the model. 60d314079dab9969343815.png
How can I make the Words model fill with data from the database (word, trans), and the Category model take data from the category column of the database?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Denis Melnikov, 2021-06-23
@Mi11er

Probably not optimal, but it will work.
If it is possible to unload the database in csv / json, then you can send this file to the server for processing.
Then iterate over the lines to make elements.
from the category

w = Words.objects.create(word=data[0])
w.category, _* = Category.objects.get_or_create(category=data[1])
w.save()

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question