Answer the question
In order to leave comments, you need to log in
How to import data into django model?
I have a database.
I need to import data into the model.
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
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 questionAsk a Question
731 491 924 answers to any question