Monday, December 20, 2010

Re: turning a Model instance into an instance of one of it's subclasses

Hmmm, I seem to have somewhat figured out what's going on.

Using Marc's example, when you instantiate u it's doctype field is set
to the default for Documents (None), since it isn't passed in. Then
when you save it, it overwrites the field in d.

So it seems the answer to my question is something like:

d = Document(doctype='whatever')
d.save()
u_kwargs = <dictionary of the fields of d>
u_kwargs.update({
'document_ptr_id': d,
'filename': 'rat.doc',
})
u = UploadedFile(**u_kwargs)
u.save()

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

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate