I need to outsource some of the attribues in the following Django model:
class TextResult(models.Model):
user = models.ForeignKey(settings.AUTH_USER_MODEL, default=1)
text = models.ForeignKey(Text)
# following fields will be in the referenced model
wpm = models.FloatField(default=0.0)
accuracy = models.FloatField(default=1.0,
validators=[MinValueValidator(0.0),
MaxValueValidator(1.0)])
to a model, that references to the specific data:
class TextResult(models.Model):
user = models.ForeignKey(settings.AUTH_USER_MODEL, default=1)
text = models.ForeignKey(Text)
typing_result = models.ForeignKey(TypingResult)
class TypingResult(models.Model):
wpm = models.FloatField(default=0.0)
accuracy = models.FloatField(default=1.0,
validators=[MinValueValidator(0.0),
MaxValueValidator(1.0)])
The problem is, that there is already some data in the database, so I have to migrate the data to the new structure, what is the easiest, cleanest way to achieve that?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…