Example #1
0
    def import_companies(self):
        csv_file = self.read_file('importer/data/companies.csv')

        print 'Importing Companies...'
        for row in csv_file:
            try:
                Company.objects.get(name=row[0])
                print 'Company', row[0], 'already registered.'
            except ObjectDoesNotExist:
                company = Company()
                company.name = row[0]
                company.save()
import json
from models.models import Company

if __name__ == '__main__':
    with open('sample_companies.json') as f:
        sample_data_as_json = json.load(f)

    for element in sample_data_as_json:
        company = Company(name=element['name'],
                          strasse=element['strasse'],
                          plz=element['plz'],
                          ort=element['ort'],
                          land=element['land'])
        company.save()