Monday, December 20, 2010

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

On Mon, Dec 20, 2010 at 4:49 PM, Marc Aymerich <glicerinu@gmail.com> wrote:
>
>
> On Mon, Dec 20, 2010 at 8:29 PM, morgan wahl <morgy.wahl@gmail.com> wrote:
>>
>> Hello all,
>>
>> I was wonder if there is a way to turn a model instance into an
>> instance of a subclass of it's class. E.g.:
>>
>> class Document(models.Model):
>>    doctype = models.CharField(max_length=256, blank=True, null=True)
>>
>> class UploadedFile(Document):
>>    filename = models.CharField(max_length=256)
>>
>> Given a Document that isn't already an UploadedFile, can I turn it
>> into one? I know at the database level it's just a matter of inserting
>> a new row into the uploadedfile table with document_ptr_id = the
>> Document's id. I've tried
>>
>
> I think that something like this should do the work:
> Document.UploadFile.filename="rat.doc"
> Document.save()
>
> --
> Marc
Um, I'm not sure what it is you're trying to demonstrate here... in my
example bits of code Document and UploadedFile are Model classes, not
instances.

>
> --
> 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.
>

--
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