263
|
1 |
import sys
|
|
2 |
from datetime import datetime
|
|
3 |
from django.core.management.base import NoArgsCommand
|
|
4 |
|
|
5 |
from django.contrib.auth.models import User
|
|
6 |
|
|
7 |
from pytask.profile.models import Profile
|
|
8 |
|
|
9 |
def seed_db():
|
|
10 |
""" a method to seed the database with random data """
|
|
11 |
|
|
12 |
|
|
13 |
for i in range(1,21):
|
|
14 |
|
|
15 |
username = 'user'+str(i)
|
|
16 |
email = username+'@example.com'
|
|
17 |
password = '123456'
|
|
18 |
dob = datetime.now()
|
|
19 |
gender = "M"
|
|
20 |
aboutme = "I am User"+str(i)
|
|
21 |
address = "I live in street"+str(i)
|
|
22 |
phonenum = "1234567890"
|
|
23 |
|
|
24 |
new_user = User.objects.create_user(username=username,
|
|
25 |
email=email,
|
|
26 |
password=password)
|
|
27 |
|
|
28 |
new_profile = Profile()
|
|
29 |
new_profile.user = new_user
|
|
30 |
new_profile.dob = dob
|
|
31 |
new_profile.aboutme = aboutme
|
|
32 |
new_profile.gender = gender
|
|
33 |
new_profile.address = address
|
|
34 |
new_profile.phonenum = phonenum
|
|
35 |
if i%2 == 0:
|
|
36 |
new_profile.rights = "CT"
|
|
37 |
elif i%3 == 0:
|
|
38 |
new_profile.rights = "CR"
|
|
39 |
new_profile.save()
|
|
40 |
|
|
41 |
class Command(NoArgsCommand):
|
|
42 |
|
|
43 |
def handle_noargs(self, **options):
|
|
44 |
""" Just copied the code from seed_db.py """
|
|
45 |
|
|
46 |
seed_db()
|