-
-
Notifications
You must be signed in to change notification settings - Fork 275
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Using non-polymorphic mixins breaks _base_manager #534
Comments
Does your mixin class need to inherit from |
Only insofar that I would like features available for both non-polymorphic and polymorphic models. I strive to keep my code DRY and currently I have to define the mixin twice, once for polymorphic and non-polymorphic models. The following is an attempt to keep things DRY, but it does not work: class BaseMixin:
created_at = models.DateTimeField(auto_now_add=True)
modified_at = models.DateTimeField(auto_now=True)
class ModelMixin(BaseMixin, models.Model):
class Meta:
abstract = True
class PolymorphicMixin(BaseMixin, PolymorphicModel):
class Meta:
abstract = True If you you check the fields defined on these models you'll get: print(ModelMixin._meta.get_fields()) # (<django.db.models.fields.BigAutoField: id>,)
print(PolymorphicMixin._meta.get_fields()) # (<django.db.models.fields.BigAutoField: id>,) As you can see If |
Here are three polymorphic models, each with different mixins:
Both
Foo
andBar
have abase_manager
ofPolymorphicManager
:However, for
Baz
, itsbase_manager
is notPolymorphicManager
:The reason I would use a non-polymorphic mixin is because I want to use it on multiple models, polymorphic and non-polymorphic alike. The only solution I've found is to duplicate my model mixin code, just swapping out
models.Model
withPolymorphicModel
. I'd rather have only one mixin, do you know if this is possible?The text was updated successfully, but these errors were encountered: