djangosqlitedjango-modelsdjango-shell

how to insert list of data into django database?


I made a list of items in string that i wanted to insert them into my Country table from shell, well wasn't successful so need some help.(i tried to add it as list and tuple but didn't work just caused more errors) I use sqlite3 database models.py

class Country(models.Model):
    #countries list
    country_name = models.CharField(max_length=100)

a list like this 'Afghanistan', 'Albania', 'Algeria', 'Andorra'


Solution

  • This should do it:

    for s in your_list: Country.objects.create(country_name= s)