I can answer for the settings part :) Make sure your project is in your PYTHONPATH environment variable and that DJANGO_SETTINGS_MODULE also exists as an environment variable. See http://www.djangoproject.com/documentation/settings/#designating-the-settings
On Jul 8, 7:15 am, Carl Karsten <[EMAIL PROTECTED]> wrote: > Russell Keith-Magee wrote: > > On 7/8/07, Carl Karsten <[EMAIL PROTECTED]> wrote: > >> Russell Keith-Magee wrote: > >>> Django users have many skills. Unfortunately, mind reading is > >>> generally not one of those skills :-) > > >> Yeah, I see what you mean. seemed obvious to me :) > > >> does django expose it's ORM so that I can do the above code (connect to > >> server, > >> execute query) and get results back that I can access using > >> object.fieldname > >> notation? (or a dict) > > > Well, depends what level you want to deal with it. > > > If you want Django to handle the full stack, then you will need to > > write a Django model that corresponds to the model you are trying to > > import. Usually not that difficult to do, but somewhat excessive > > effort for a temporary measure. > > Ok, not that big a deal. even with "inspectdb will help somewhat," it still > seems more trouble than it is worth. > > > Another alternative is to use the cursor to retrieve a row, then feed > > that row directly into the Django object of choice: > > > for row in cursor.fetchAll(): > > user = User(*row) > > user.save() > > > This assumes that the field names coming back from the cursor > > correspond to the field names in the object you are saving; if this > > isn't the case, you may need to do some dictionary munging on the *row > > part. > > Unfortunately, I need to do some mucking, including field names with spaces. > geez. > > > > >> This code just bothers me: > >> user = User.objects.create_user( member[5], member[4], member[6] ) > > > Why? It's just a manager shorthand for: > > > now = datetime.datetime.now() > > user = self.model(None, username, '', '', email.strip().lower(), > > 'placeholder', False, True, False, now, now) > > user.set_password(password) > > user.save() > > the User.objects.create_user() part is great. the member[5], member[4], > member[6] magic numbers bothers me. > > I was hoping for > user = User.objects.create_user( member.username, member.pw, > member.first_name ) > > > > >> Also, django.contrib.auth.models import User needs settings imported, and > >> import-users.py is in a util/ dir under the 'home dir' that holds > >> settings.py. > >> What is a good way to reference ../settings.py? > > > Something like: > > > from myproject import settings as myproject_settings > > like that, only completely different :) > > When I run my code (below) I get: > > self._target = Settings(settings_module) > File "/usr/lib/python2.5/site-packages/django/conf/__init__.py", line 83, > in > __init__ > raise EnvironmentError, "Could not import settings '%s' (Is it on > sys.path? > Does it have syntax errors?): %s" % (self.SETTINGS_MODULE, e) > EnvironmentError: Could not import settings 'settings' (Is it on sys.path? > Does > it have syntax errors?): No module named settings > > I am assuming there are a few bad ways to solve this, and I am trying to > avoid them. > > also, (still someone on topic, given my vague subject) > Is the profile=... profile.save() look right? I'm not too sure what order the > new/new/save/save should be done in. > > Carl K > > # migrate.py > # migrates data from RidgeMoorJonas.Member to django.auth_user > # uses the django user api, > # mainly to create the password based on the current one. > > from django.contrib.auth.models import User > import MySQLdb > > con = MySQLdb.connect(user='u', passwd='v' db='src' ) > cur=con.cursor() > > # reset the tables > cur.execute("truncate auth_user") > cur.execute("truncate eventcal_event") > > # Create django Users > cSql=""" > select MemberNumber, Surname, `Given name`, > `Familiar Name`, `Email Address` > UserID, UserPassword, Telephone > from Member limit 1 > """ > cur.execute(cSql) > members = cur.fetchall() > for member in members: > # user = User.objects.create_user('john', '[EMAIL PROTECTED]', > 'johnpassword') > user = User.objects.create_user( member[5], member[4], member[6] ) > user.first_name=member[2] > user.last_name = member[1] > profile = UserProfile.objects.create(user=user) > profile.phone_number=member[7] > user.save() > profile.save() --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---