title: I want to read data from text file and save it to database in Django
body: <p>I am new to <code>Django</code> and <code>Python</code>. I want to read data from text file and save it to <code>database</code>.</p>
  
  <p>Input file example:</p>
  
  <pre><code>E Alan Marshall 121 55.26 
  E Bob Marley 122 66.78
  M Ted Smith Marketing 123 76.78 
  M Ron Barly Production 124 86.78
  </code></pre>
  
  <p>I have described <code>models</code> as follows:</p>
  
  <pre><code>class Employee(models.Model):   
          first = models.CharField(max_length=20)
          last = models.CharField(max_length=20)
          id = models.IntegerField()
          pay = models.DecimalField(max_digits=12, decimal_places=2)
  
  class Manager(models.Model):
          first = models.CharField(max_length=20)
          last = models.CharField(max_length=20)
          department = models.CharField(max_length=20)
          id = models.IntegerField()
          pay = models.DecimalField(max_digits=12, decimal_places=2)  
  </code></pre>
  
  <p>I receive data in the form of a text file and I read the data by parsing the string. The first character tells me the type of class data to expect (e.g. E means Employee class object data, M means manager class object data)
  Once we know the type of data, the sequence in which the variables occur are fixed. Means if I tokenize string with 'space' as delimiter, for Employee class, first element is first Name, next is last name, next is employee id, next is pay</p>
  
  <p>I want to write code in <code>python</code> which will parse the input file and will create objects of the respective class.
  I should maintain the type of class variable too</p>
  
  <pre><code>type of
              first is string
              last is string
              id is interger
              pay is float
              department is string
  </code></pre>
  
  <p>I was planning to write generic function to parse and create the objects of classes.
  It will read file line by line, tokenize the line and will call function to generate object of the class.
  <code>"generateClassObject"</code> function will take dictionary of variable name and their type as input. (e.g. for <code>Employee class {"first":"string", "last":"string", "id":"integer", "pay":"float" }</code>, for Manager <code>class {"first":"string", "last":"string", "department":"string" "id":"integer", "pay":"float" }</code>)
  and will return the class object.</p>
  
  <p>The function will look something like</p>
  
  <pre><code>generateClassObject(className, dictionary, tokenizedData):
      # instantiate class object based on className (How to do this?)
      # read dictionary one by one and assign value to respective variable of
        # class object from tokenizedData by converting string data to proper
        # type (How to do this?)
      # save class object to database (I know how to do this)
  </code></pre>
  
  <p>Is it possible create objects of class <code>dynamically</code> in <code>python</code>?.
  How to instantiate class object based on <code>className</code>?.
  How to convert string data into proper datatype if we know the proper datatype in <code>python</code>? .</p>