Extension to typeclass fix, to allow non-typeclass mixins
This commit is contained in:
parent
fff80c4752
commit
ad59dde130
1 changed files with 16 additions and 5 deletions
|
|
@ -109,17 +109,28 @@ class TypeclassBase(SharedMemoryModelBase):
|
||||||
if not hasattr(bases, "__iter__"):
|
if not hasattr(bases, "__iter__"):
|
||||||
bases = [bases]
|
bases = [bases]
|
||||||
for base in bases:
|
for base in bases:
|
||||||
if base._meta.proxy or base._meta.abstract:
|
try:
|
||||||
for kls in base._meta.parents:
|
if base._meta.proxy or base._meta.abstract:
|
||||||
return _get_dbmodel(kls)
|
for kls in base._meta.parents:
|
||||||
return base
|
return _get_dbmodel(kls)
|
||||||
|
except AttributeError:
|
||||||
|
# this happens if trying to parse a non-typeclass mixin parent,
|
||||||
|
# without a _meta
|
||||||
|
continue
|
||||||
|
else:
|
||||||
|
return base
|
||||||
|
return None
|
||||||
|
|
||||||
dbmodel = _get_dbmodel(bases)
|
dbmodel = _get_dbmodel(bases)
|
||||||
|
|
||||||
|
if not dbmodel:
|
||||||
|
raise TypeError(f"{name} does not appear to inherit from a database model.")
|
||||||
|
|
||||||
|
|
||||||
# typeclass proxy setup
|
# typeclass proxy setup
|
||||||
# first check explicit __applabel__ on the typeclass, then figure
|
# first check explicit __applabel__ on the typeclass, then figure
|
||||||
# it out from the dbmodel
|
# it out from the dbmodel
|
||||||
if dbmodel and "__applabel__" not in attrs:
|
if "__applabel__" not in attrs:
|
||||||
# find the app-label in one of the bases, usually the dbmodel
|
# find the app-label in one of the bases, usually the dbmodel
|
||||||
attrs["__applabel__"] = dbmodel._meta.app_label
|
attrs["__applabel__"] = dbmodel._meta.app_label
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue