I am not really sure exactly what you are trying to accomplish here, if you want to 'create a load of Places based on what is in RawPlaces but with a resource' wouldn't a FK or M2M (depending on your cardinality requirements) relationship to RawPlaces within Resource simplify this process? I am not sure of the point of the apparent redundancy of Places and RawPlaces.
My (limited) understanding of OneToOne relationships is that it is usually used when an object extends another object, i.e. AppUser extends User or from the model-api doc Restaurant extends Place. Do you really want Place to extend Resource? Another solution is to have Place have a M2M relationship to Resource, which sounds more logical to me (of course, I have no idea what your app is designed to do) as any Place (probably) has more than one Resource. hth, -richard On 5/21/08, Col Wilson <[EMAIL PROTECTED]> wrote: > > > I'm brand new to django from rails, and I'm a bit stuck trying to get > relationships to work. RawPlaces table is full of place names and data > already. > > My model looks like this: > > from django.db import models > import sys, os > > class RawPlace(models.Model): > name = models.CharField(max_length=64) > lat = models.IntegerField() > lng = models.IntegerField() > population = models.IntegerField() > country = models.IntegerField() > region = models.IntegerField() > > class Admin: > pass > > def __unicode__(self): > return self.name > > class Resource(models.Model): > gold = models.IntegerField(default=0) > food = models.IntegerField(default=0) > recruits = models.IntegerField(default=0) > > class Admin: > pass > > def randomize(self, population=0): > gold = random.randint(0, population) > food = random.randint(0, population) > recruits = random.randint(0, population) > > class PlaceManager(models.Manager): > > def randomize(self): > for p in Place.objects.all(): > p.delete() > for raw in RawPlace.objects.all(): > print raw > r = Resource() > r.save() > p = Place(lat=raw.lat, lng = raw.lng, > population=raw.population, > country=raw.country, region=raw.region, resource=r) > p.save() > return Place.objects.all() > > class Place(models.Model): > name = models.CharField(max_length=64) > lat = models.IntegerField() > lng = models.IntegerField() > population = models.IntegerField() > country = models.IntegerField() > region = models.IntegerField() > resource = models.OneToOneField(Resource, primary_key=True) > objects = PlaceManager() > > class Admin: > pass > > def __unicode__(self): > return self.name > > > So I want to create a load of Places based on what's in RawPlaces, but > with a Resource: > > >>> from places.models import Place, RawPlace, Resource > >>> Place.objects.randomize() > Saint Martin's > Traceback (most recent call last): > File "<console>", line 1, in <module> > File "C:\local\workspaces\project4\places\models.py", line 42, in > randomize > r.save() > File "C:\Python25\Lib\site-packages\django\db\models\base.py", line > 272, in save > self.save_base() > File "C:\Python25\Lib\site-packages\django\db\models\base.py", line > 336, in save_base > transaction.commit_unless_managed() > File "C:\Python25\Lib\site-packages\django\db\transaction.py", line > 136, in commit_unless_managed > connection._commit() > File "C:\Python25\Lib\site-packages\django\db\backends\__init__.py", > line 20, in _commit > return self.connection.commit() > OperationalError: SQL logic error or missing database > > help? > > > > --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---