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 the Word, or do you want it to find the Verb. And how do you want to treat words (if text words they are) like "record", which is a noun (keep a record), a verb (record a performance) and an adjective (record crowd), at the very least. (Note that the pronunciation of the verb is different, if you were thinking of storing pronunciation info in the Word.)
If you have separate models, you could certainly write the method that initializes a completely separate sub-class instance from the instance data of the super class instance. You could also do some magic using the field list available in the manager (which has the problem, IIRC, that it is not a public interface) to know which data to copy, though I'm of the explicit is better than implicit camp. So, I guess that I really don't know enough about your problem to suggest a detailed technique. I suspect that if it were me, I'd probably be using a foreign key reference from Verb to Word, rather than sub-classing. Bill On Wed, Jun 22, 2011 at 9:45 PM, Matt Gardner <drai...@gmail.com> wrote: > 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 example, I might have code like this: > >>>> word = Word.objects.get(pk=[input from user]) >>>> verb = Verb.createFromSuperclassInstance(word) >>>> verb.save() > > The only problem is that I know of no such > "createFromSuperclassInstance" method, nor where to look for it. I do > know how to do this through the database itself (just add a row to the > verb table with the correct foreign key), but I was hoping django > would provide some nice way to do it without me having to explicitly > write SQL. The Verb class's __init__ method creates a new Word > instance, so that doesn't work, unless there's a way to use it that I > don't know about. > > Any help? > > Thanks, > Matt > > -- > 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.