So long as it *IS* one to one. I.e.; there are no Word-s that are both a Verb and a Noun.
I'd sill go with a foreign key field in Verb (and Noun, etc.) referring to Word. I think that you can even mark it unique, meaning that only one Verb can refer to any given Word, but both a Noun and a Verb could refer to the same Word. But you know your needs. Bill On Thu, Jun 23, 2011 at 8:44 PM, Matthew Gardner <mj...@byu.edu> wrote: > Thanks for your input, Bill, I appreciate it. I think I'm just going to > take a hit and switch to an explicit OneToOneField instead of trying to make > this work with inheritance. The other way things will just work, because > django's built to make it work, but doing it with inheritance is difficult > and ugly. Thanks for helping me see that. I wonder if it's worth putting a > note in the django docs that in some cases a OneToOneField is more > appropriate than inheritance, given some of these problems (and the fact > that other people have had the same problem, as I noted with my link to a > previous post to django-users). Anyway, thanks again for your help. > Matt > > On Thu, Jun 23, 2011 at 3:47 PM, Bill Freeman <ke1g...@gmail.com> wrote: >> >> 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. >> > > -- > 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.