models.py:
class root(models.Model):
uid_string = models.CharField(max_length=255, unique=True)
class tree(models.Model):
uid_string = models.ForeignKey(root, to_field='uid_string', db_column='uid_string')
class shrub(models.Model):
uid_string = models.ForeignKey(root, to_field='uid_string')
obviously, the column in shrub
will be uid_string_id
while the column in tree
will bee uid_string
. the _id appendix is supressed.
If I now do a
rootentry = root(uid_string = "text")
root.save()
I get different behaviour doing the following queries:
>>> shrubentry = shrub(uid_string_id = rootentry.uid_string)
>>> treeentry = tree(uid_string = rootentry.uid_string)
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "/usr/local/lib/python2.6/site-packages/django/db/models/base.py", line 328, in __init__
setattr(self, field.name, rel_obj)
File "/usr/local/lib/python2.6/site-packages/django/db/models/fields/related.py", line 318, in __set__
self.field.name, self.field.rel.to._meta.object_name))
ValueError: Cannot assign "'text'": "tree.uid_string" must be a "root" instance.
>>>
obviously rootentry.uid_string
is text