You are right, and my sample function above "extend" also works. The
problem is that I had a read-only property in my child model that had
the same name as one of the fields in the parent model. I had not
noticed that until I dug deeper to investigate the issue :-(
thanks for your help.
--
Medha
I did the following, it works fine:
from django.db import models
class Place(models.Model):
name = models.CharField(max_length=50)
address = models.CharField(max_length=80)
def __unicode__(self):
return self.name
# you can call this on any model object
def object_as_dict(mo
Whoops... get should be filter
existing_ct_as_dict=ContentType.objects.filter(pk=ct_pk).values()[0]
On Apr 30, 9:04 am, AmanKow <[EMAIL PROTECTED]> wrote:
> Assuming ACT is your class name:
>
> ct = #... get the content type instance to extend here, or obtain the
> pk in whatever way
> ct_pk
Trying to use this idea, I created the following function:
def extend(parent_class, parent_id, child_class, **kwargs):
p = parent_class.objects.filter(pk=parent_id).values()[0]
p.update(kwargs)
c = child_class(**p)
return c
but that still does not work. It throws an "AttributeErr
Hmmm... this seems to be a common issue... extending already existing
records
Would be nice if there were a way to create the child, specify the pk
and do a "save child only"
On Apr 30, 9:04 am, AmanKow <[EMAIL PROTECTED]> wrote:
> Assuming ACT is your class name:
>
> ct = #... get the content ty
Assuming ACT is your class name:
ct = #... get the content type instance to extend here, or obtain the
pk in whatever way
ct_pk= ct.pk
existing_ct_as_dict=ContentType.objects.get(pk=ct_pk).values()[0]
act = ACT(**existing_ct_as_dict #, your extended keyword vars)
act.save()
You must fetch and s
Hi,
QS-rf in general and model inheritance in particular are really cool.
I have been waiting for them for a long time, thanks :-)
I am trying now to use them. And one question I have is the following:
for multi-table inheritance, (using the example from the
documentation,) let's say that we hav
7 matches
Mail list logo