How to import CSV file to django models
<p>I have Django models like this</p>

<pre><code>class Revo(models.Model):           
    SuiteName = models.CharField(max_length=255)
    Test_Case = models.CharField(max_length=255)
    FileName = models.CharField(max_length=255)
    Total_Action = models.CharField(max_length=255)
    Pass = models.CharField(max_length=255)
    Fail = models.CharField(max_length=255)
    Exe_Time = models.CharField(max_length=255)
    Result = models.CharField(max_length=255)
    create_date = models.DateTimeField(default=datetime.datetime.now)

    class Meta:
        verbose_name_plural = "Revo"
</code></pre>

<p>I have CSV file like this</p>

<pre><code>SuiteName,Test Case,FileName,Total Action,Pass,Fail,Exe Time,Result
DEMO_TEST_SUITE,Testcase 1,file1,82,0,108,0:27:52,FAIL
DEMO_TEST_SUITE,Testcase 2,file2,86,0,108,0:27:52,FAIL
DEMO_TEST_SUITE,Testcase 3,file3,820,0,108,0:27:52,FAIL
DEMO_TEST_SUITE,Testcase 4,file4,182,0,108,0:27:52,FAIL
DEMO_TEST_SUITE,Testcase 5,file5,102,0,108,0:27:52,FAIL
DEMO_TEST_SUITE,Testcase 6,file6,111,0,108,0:27:52,FAIL
</code></pre>

<p>How do I import this csv data into my django models? Also, is there any way to plot graphs out this data directly from database?</p>

<p>You can use the built in <a href="https://docs.python.org/3/library/csv.html" rel="nofollow">csv module</a> to turn your csv file into a <a href="https://docs.python.org/3/library/csv.html#csv.DictReader" rel="nofollow">dict like object</a>:</p>

<pre><code>import csv

with open('import.csv') as csvfile:
    reader = csv.DictReader(csvfile)
    for row in reader:
        # The header row values become your keys
        suite_name = row['SuiteName']
        test_case = row['Test Case']
        # etc....

        new_revo = Revo(SuiteName=suite_name, TestCase=test_case,...)
        new_revo.save()
</code></pre>

python django csv graph