0062_clear_secrets_changelog.py 783 B

1234567891011121314151617181920212223242526
  1. from django.db import migrations
  2. def clear_secrets_changelog(apps, schema_editor):
  3. """
  4. Delete all ObjectChange records referencing a model within the old secrets app (pre-v3.0).
  5. """
  6. ContentType = apps.get_model('contenttypes', 'ContentType')
  7. ObjectChange = apps.get_model('extras', 'ObjectChange')
  8. content_type_ids = ContentType.objects.filter(app_label='secrets').values_list('id', flat=True)
  9. ObjectChange.objects.filter(changed_object_type__in=content_type_ids).delete()
  10. class Migration(migrations.Migration):
  11. dependencies = [
  12. ('extras', '0061_extras_change_logging'),
  13. ]
  14. operations = [
  15. migrations.RunPython(
  16. code=clear_secrets_changelog,
  17. reverse_code=migrations.RunPython.noop
  18. ),
  19. ]