Re: Creating an instance of a subclass when superclass instance already exists

2011-06-24 Thread Bill Freeman
Sorry. I'd been thinking in terms of a not null constraint and confusing myself that it would apply in both directions. Bill On Fri, Jun 24, 2011 at 10:25 AM, Tom Evans wrote: > On Fri, Jun 24, 2011 at 3:15 PM, Bill Freeman wrote: >> So long as it *IS* one to one.  I.e.; there are no Word-s th

Re: Creating an instance of a subclass when superclass instance already exists

2011-06-24 Thread Tom Evans
On Fri, Jun 24, 2011 at 3:15 PM, Bill Freeman wrote: > 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

Re: Creating an instance of a subclass when superclass instance already exists

2011-06-24 Thread Bill Freeman
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

Re: Creating an instance of a subclass when superclass instance already exists

2011-06-23 Thread Matthew Gardner
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

Re: Creating an instance of a subclass when superclass instance already exists

2011-06-23 Thread Bill Freeman
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 tab

Re: Creating an instance of a subclass when superclass instance already exists

2011-06-23 Thread Bill Freeman
I'm still confused about what you have (what form of inheritance you are using. In your database, are there both a Word table and a Verb table? Or is there just a (set of) Verb (and Noun and Adjective, etc.) table(s), derived from a non-Model Word class? If there's a Noun instance "record" and a

Re: Creating an instance of a subclass when superclass instance already exists

2011-06-23 Thread Matthew Gardner
I'm using django's model inheritance. Sorry I wasn't clear. So there's a Word model and a Verb model. class Word(models.Model): # Word stuff class Verb(Word): # Verb-specific stuff The way django handles this is to create a word table and a verb table. The verb table has a reference t

Re: Creating an instance of a subclass when superclass instance already exists

2011-06-23 Thread Matthew Gardner
On Thu, Jun 23, 2011 at 2:18 PM, Matthew Gardner 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 th

Re: Creating an instance of a subclass when superclass instance already exists

2011-06-23 Thread Matthew Gardner
On Thu, Jun 23, 2011 at 11:47 AM, Tom Evans wrote: > On Thu, Jun 23, 2011 at 4:36 PM, Matthew Gardner wrote: > > At this point, all I really want to do is add a row to the verb table > that > > contains the correct foreign key, without creating a new row in the word > > table. > > Verb.objects.cr

Re: Creating an instance of a subclass when superclass instance already exists

2011-06-23 Thread Tom Evans
On Thu, Jun 23, 2011 at 4:36 PM, Matthew Gardner wrote: > At this point, all I really want to do is add a row to the verb table that > contains the correct foreign key, without creating a new row in the word > table. Verb.objects.create(word=word) doesn't fulfill these criteria? Cheers Tom --

Re: Creating an instance of a subclass when superclass instance already exists

2011-06-23 Thread Matthew Gardner
Thanks, Bill, for your comments. Shortly after I posted here I did a little more digging and found this thread from six months ago that described exactly my problem: http://groups.google.com/group/django-users/browse_thread/thread/9400999651577bc2/8cc4fe267128d6a3 That thread didn't seem to have

Re: Creating an instance of a subclass when superclass instance already exists

2011-06-23 Thread Bill Freeman
First, if, despite being related by inheritance, Word and Verb are separate models, they have separate tables. Then if you do create a Verb, the Word still exists, unless you delete it. Is that what you want? If both are to exist, were you hoping that a query for the same key would still find th

Creating an instance of a subclass when superclass instance already exists

2011-06-22 Thread Matt Gardner
Hello all, I have a model hierarchy in my django app, and there is one very important task that I do not know how to do. I have a bunch of instances of the superclass (Word is the model name), and on input from a user I want to create a subclass instance (Verb) from that superclass instance. For