Advertisement
Guest User

Untitled

a guest
Nov 15th, 2013
262
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.51 KB | None | 0 0
  1. import MySQLdb
  2. import django
  3. from django.conf import settings
  4. settings.configure()
  5. from django.contrib.contenttypes.models import ContentType
  6.  
  7. def main():
  8. user_type = ContentType.objects.get(app_label='ZingyHome', model='User')
  9. User = user_type.model_class()
  10. conn = MySQLdb.connect(host='127.0.0.1', user='root', passwd='root', db='zingyhomes')
  11. cursor = conn.cursor(MySQLdb.cursors.DictCursor)
  12. cursor.execute("select * from tbl_personaldetails")
  13. rows = cursor.fetchall()
  14. for row in rows:
  15. user = User.objects.create(
  16. id = row['customerId'],
  17. first_name = row['firstName'],
  18. last_name = row['lastName'],
  19. email = row['emailAddress'],
  20. token = row['verificationCode'],
  21. user_type = row['type'],
  22. is_email_validated = True if row['emailVerification'] is 1 else False,
  23. date_joined = row['addDate'],
  24. date_modified = row['lastUpdated'],
  25. phone = row['phone'],
  26. address = row['address'],
  27. Iam = row['Iam'],
  28. about_yourself = row['about_yourself'],
  29. image = row['imagePath'],
  30. pincode = row['pin'],
  31. mailchimplistid = row['mailchimpListId'],
  32. Key_project_holded = row['keyProjectHolded'],
  33. provide_service_in = row['provide_service_in'],
  34. )
  35. country, country_created = Country.objects.get_or_create(name=row['country'])
  36. state, state_created = State.objects.get_or_create(name=row['state'])
  37. city, city_created = City.objects.get_or_create(name=row['city'])
  38. user.country = country
  39. user.state = state
  40. user.city = city
  41. user.set_password(row['passwords'])
  42. user.save()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement