So, we're talking about "Multi-table inheritance"
(https://docs.djangoproject.com/en/1.3/topics/db/models/#multi-table-inheritance).
 Note that this uses "an automatically-created OneToOneField".

What you really want to do is to create a python instance of the Verb
class.  It's id (in the Verb table) will be empty, meaning the Verb
row will get created on save().  If the field that Verb uses to refer
to Word is already set at save() time, the ORM *MIGHT* just happily
save Verb, and either not save the unmodified Word (I'm pretty sure
that you must have an instantiation of the Word instance lying
around), or, at worst, just update it with unchanged data, rather than
creating a new instance.  You'll have to experiment, unless an ORM
expert speaks up.

One problem is how to set that reference in the Verb object.  I don't
think you get a 'word' attribute on a Verb object, do you?  If worst
comes to worse you can access the attribute by using
v.__dict__['attribute_name'] where v is a Verb instance.  You can poke
around in pdb on a Verb instance that was made and already saved in
the normal way to see how things are named and represented.

You are probably on your own to assure that you don't add more than
one Verb to a given Word.  Some of the reverse lookup stuff may get
confused if there are more than one.  I doubt that the uniqueness
constraint in the DB functions in that direction.  Beware multiple
threads - you may need to play with transactions and roll backs.

And, of course, things could change in a future version even if this works now.

Good luck, Bill

On Thu, Jun 23, 2011 at 2:22 PM, Matthew Gardner <mj...@byu.edu> wrote:
> On Thu, Jun 23, 2011 at 2:18 PM, Matthew Gardner <mj...@byu.edu> wrote:
>>
>> class Verb(models.Model):
>>     word = models.ForeignKey('Word')
>>     # Verb-specific stuff
>
> Sorry, this is more accurate:
> class Verb(models.Model):
>     word = models.OneToOneField('Word')
>     # verb-specific stuff
>
> --
> 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
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>

-- 
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 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to