Make it possible to extend TypedModel
Closed this issue · 3 comments
jacobjove commented
I'd like to extend TypedModel
with another abstract model class.
I've tried the following:
from typedmodels.models import TypedModel
from typedmodels.models import TypedModelMetaclass
class MyTypedModel(TypedModel, metaclass=TypedModelMetaclass):
pass
class Meta:
abstract = True
Then I make a model named Place
inherit from MyTypedModel
and from another abstract model class (Module
, which adds a number of model fields such as slug
):
class Place(MyTypedModel, Module):
"""Where something has happened."""
name = models.CharField(
verbose_name=_('name'),
blank=True,
max_length=NAME_MAX_LENGTH,
unique=True,
)
location = models.ForeignKey(
to='self',
related_name='places',
blank=True,
null=True,
on_delete=models.PROTECT,
)
preposition = models.CharField(max_length=2, choices=PREPOSITION_CHOICES, default='in')
class Meta:
unique_together = ['name', 'location']
objects = TypedModelManager()
slug_base_fields = ('string',)
However, this inheritance results in a TypeError:
File "/usr/local/lib/python3.9/site-packages/typedmodels/models.py", line 139, in __new__
cls = super(TypedModelMetaclass, meta).__new__(
File "/usr/local/lib/python3.9/site-packages/django/db/models/base.py", line 177, in __new__
raise TypeError(
TypeError: Abstract base class containing model fields not permitted for proxy model 'Place'.
I'm on Django 3.2.
Any direction on this would be much appreciated!
craigds commented
Thanks for the issue.
I'm having trouble understanding what this does. Could you share the Place model too? Is Place a direct subclass of MyTypedModel ?
craigds commented
Also what version of Django is this?