django create username and password from csv

Solutions on MaxInterview for django create username and password from csv by the best coders in the world

showing results for - "django create username and password from csv"
Leane
17 Mar 2019
1import csv, sys, os, django
2
3
4project_dir = "/parcare/src/"
5sys.path.append(project_dir)
6os.environ['DJANGO_SETTINGS_MODULE'] = 'adp_parking.settings'
7# os.environ.setdefault("DJANGO_SETTINGS_MODULE", __file__)
8import django
9django.setup()
10
11
12from django.contrib.auth import authenticate
13from django.contrib import admin
14from django.contrib.auth.models import User
15
16from django.contrib.auth import get_user_model
17from django.conf import settings
18User = get_user_model()
19
20file = 'import.csv'
21
22data = csv.reader(open(file), delimiter=",")
23for row in data:
24    if row[0] != "Number":
25        # Post.id = row[0]
26        Post=User()
27        Post.password = row[1]
28        Post.last_login = "2018-09-27 05:51:42.521991"
29        Post.is_superuser = "0"
30        Post.username = row[2]
31        Post.first_name = row[3]
32        Post.email = row[4]
33        Post.is_staff = "1"
34        Post.is_active = "1"
35        Post.date_joined = "2018-09-27 05:14:50"
36        Post.last_name=row[5]
37        Post.save()
38
similar questions