Often we need to change the way a piece of data is modelled on our backend. Recently I was faced with refactoring a large model into component pieces and needed a cheat sheet for the best practices to use when migrating live data on our production server to a new schema.
This is an explanation of how to perform an extractClass refactoring from within the context of a Django models.Model. For this tutorial, I'll assume you are familiar with schemamigration using South.
The basic purpose of this type of refactoring is usually one of the following:
- to DRY up your data model, such that a similar schema can be reused in multiple places
- to implement a One to Many relationship on data that is currently One to One, and tightly coupled to an existing Model