I've got tables like the following (Django model definition, with a postgres database underlying it):
class Person(models.Model):
id = models.IntegerField(primary_key=True)
name = models.CharField(max_length=300)
class Owner(models.Model):
id = models.IntegerField()
person = models.ForeignKey(Person)
I use a Python script to set up my database from CSV files. The raw files list Owners with an integer id and an integer 'person' field, which maps to the integer in Person.id.
However, given that the 'person' column in Owner expects a Person object, how do I write a raw SQL string to insert value into Owner?
owner_id = 665
person_id = 330
sql_string = 'INSERT INTO owner (id, person) VALUES (' +
sql_string += owner_id + ', ' + ???? + ');'