djangodjango-modelsdjango-errorsdjango-inheritance

Django - inheritance


I have a problem with inheritance :

class ContainPj(models.Model):
    id_scribe=models.IntegerField()
    id_pj=models.IntegerField()

    class Meta :
        abstract = True


class Member(ContainPj):
    pass


class Collab(Member):
    pass

I make :
m = Member(id_scribe=..., id_pj=...)
c = Collab(m)
c.save()
and thither :
TypeError: int() argument must be a string or a number, not 'Member'

I don't understand... and I research on the web and I haven't found one solution...


Solution

  • If you want to populate Collab fields from Member instance then you should do it explicitly:

    c = Collab(id_scribe=m.id_scribe, id_pj=m.id_pj)