delete_view_model.py 1.0 KB

12345678910111213141516171819202122232425262728
  1. from django.db.migrations.operations.models import DeleteModel
  2. class PostgresDeleteViewModel(DeleteModel):
  3. """Deletes the specified view model."""
  4. def database_forwards(self, app_label, schema_editor, from_state, to_state):
  5. """Apply this migration operation forwards."""
  6. model = from_state.apps.get_model(app_label, self.name)
  7. if self.allow_migrate_model(schema_editor.connection.alias, model):
  8. schema_editor.delete_view_model(model)
  9. def database_backwards(
  10. self, app_label, schema_editor, from_state, to_state
  11. ):
  12. """Apply this migration operation backwards."""
  13. model = to_state.apps.get_model(app_label, self.name)
  14. if self.allow_migrate_model(schema_editor.connection.alias, model):
  15. schema_editor.create_view_model(model)
  16. def describe(self):
  17. """Gets a human readable text describing this migration."""
  18. description = super().describe()
  19. description = description.replace("model", "view model")
  20. return description