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
Attributes aren't inherited by subclasses #140
Comments
I think there is an PR that I think related to this: https://github.com/bmihelac/django-import-export/pull/123 Specific code: However for that pull request misses tests and have some unrelated commits. |
I'm working on a replacement PR to solve this issue, which doesn't have any of the other stuff. It also allows Meta attributes to be inherited so that One thing I'd like you to consider... what do we do with unauthorized Meta attributes? For example, I have a custom class BaseResource(resources.ModelResource):
parent_field = fields.Field(attribute='parent__base_field', readonly=True)
class Meta:
model = BaseModel
insert_only = True # This is a custom attribute If I change the way the I see three approaches:
Thoughts? |
@rhunwicks I am not sure. Would like to follow Django practices to reduce possibility of surprises. How does other libraries handle this? |
I'm not aware of any other libraries that are doing Meta inheritance. I would lean towards copying the attributes because:
|
Please disregard my previous comments. I had somehow managed to install my packages using an old requirements.txt file. Everything works as expected. Thanks. |
I have a base model and a set of subclasses of the model. As you might expect, when I create the import/export ModelResources for those subclass models there is a lot of duplicated code related to the base model. I'd like to move that code into a base ModelResource and then subclass it. For example:
Unfortunately, when I tried this the
fields.Field
attributes on the parentBaseResource
aren't inherited on theSubclassResource
. I think this is because theDeclarativeMetaclass.__new__()
only copies attributes passed in directly and doesn't loop throughbases
and add them from there. However, I'm not familiar enough with metaclass programming or django-import-export to know the best way to fix it.The text was updated successfully, but these errors were encountered: