Created
March 18, 2020 06:56
Star
You must be signed in to star a gist
inheritance.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Add fields from abstract base class if it wasn't overridden. | |
for field in parent_fields: | |
if (field.name not in field_names and | |
field.name not in new_class.__dict__ and | |
field.name not in inherited_attributes): | |
new_field = copy.deepcopy(field) | |
new_class.add_to_class(field.name, new_field) | |
# Replace parent links defined on this base by the new | |
# field. It will be appropriately resolved if required. | |
if field.one_to_one: | |
for parent, parent_link in base_parents.items(): | |
if field == parent_link: | |
base_parents[parent] = new_field | |
# Pass any non-abstract parent classes onto child. | |
new_class._meta.parents.update(base_parents) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment