Added seed_db
authorNishanth Amuluru <nishanth@fossee.in>
Fri, 07 Jan 2011 11:00:22 +0530
changeset 25 48d68e75e9cc
parent 24 d152c2211a3a
child 26 8c2376baee94
Added seed_db
profile/__init__.pyc
profile/forms.pyc
profile/management/__init__.py
profile/management/commands/__init__.py
profile/management/commands/seed_db.py
profile/models.pyc
Binary file profile/__init__.pyc has changed
Binary file profile/forms.pyc has changed
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/profile/management/__init__.py	Fri Jan 07 11:00:22 2011 +0530
@@ -0,0 +1,1 @@
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/profile/management/commands/seed_db.py	Fri Jan 07 11:00:22 2011 +0530
@@ -0,0 +1,46 @@
+import sys
+from datetime import datetime
+from django.core.management.base import NoArgsCommand
+
+from django.contrib.auth.models import User
+
+from pytask.profile.models import Profile
+
+def seed_db():
+    """ a method to seed the database with random data """
+    
+    
+    for i in range(1,21):
+        
+        username = 'user'+str(i)
+        email = username+'@example.com'
+        password = '123456'
+        dob = datetime.now()
+        gender = "M"
+        aboutme = "I am User"+str(i)
+        address = "I live in street"+str(i)
+        phonenum = "1234567890"
+
+        new_user = User.objects.create_user(username=username,
+                                            email=email,
+                                            password=password)
+
+        new_profile = Profile()
+        new_profile.user = new_user
+        new_profile.dob = dob
+        new_profile.aboutme = aboutme
+        new_profile.gender = gender
+        new_profile.address = address
+        new_profile.phonenum = phonenum
+        if i%2 == 0:
+            new_profile.rights = "CT"
+        elif i%3 == 0:
+            new_profile.rights = "CR"
+        new_profile.save()
+
+class Command(NoArgsCommand):
+    
+    def handle_noargs(self, **options):
+        """ Just copied the code from seed_db.py """
+        
+        seed_db()
Binary file profile/models.pyc has changed