Created
July 26, 2023 07:32
-
-
Save strokirk/6e0e5583b08b61a64bc7b29c823b567a to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| from django.core.management.commands.makemigrations import Command as BaseCommand | |
| from django.db.migrations.autodetector import MigrationAutodetector | |
| def monkeypatch(patient, key): | |
| original = getattr(patient, key) | |
| def foo(func): | |
| def inner(*args, **kwargs): | |
| return func(original, *args, **kwargs) | |
| setattr(patient, key, inner) | |
| return inner | |
| return foo | |
| EXCLUDE = [ | |
| "blank", | |
| "choices", | |
| "editable", | |
| "error_messages", | |
| "help_text", | |
| "local_fs_settings", | |
| "storage", | |
| "upload_to", | |
| "validators", | |
| "verbose_name", | |
| "related_name", | |
| ] | |
| @monkeypatch(MigrationAutodetector, "deep_deconstruct") | |
| def deep_deconstruct(original, *args, **kwargs): | |
| ret = original(*args, **kwargs) | |
| if isinstance(ret, tuple) and len(ret) == 3: | |
| field_kwargs = ret[2] | |
| if isinstance(field_kwargs, dict): | |
| for name in EXCLUDE: | |
| field_kwargs.pop(name, None) | |
| return ret | |
| class Command(BaseCommand): | |
| pass |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment