class ModelMixinCallStckMngr(CallStackMixin, models.Model): """ Test Model class which uses both CallStackManager, and CallStackMixin """ # override Manager objects objects = CallStackManager() id_field = models.IntegerField()
class StudentModuleHistory(CallStackMixin, models.Model): """Keeps a complete history of state changes for a given XModule for a given Student. Right now, we restrict this to problems so that the table doesn't explode in size.""" objects = CallStackManager() HISTORY_SAVING_TYPES = {'problem'} class Meta(object): app_label = "courseware" get_latest_by = "created" student_module = models.ForeignKey(StudentModule, db_index=True) version = models.CharField(max_length=255, null=True, blank=True, db_index=True) # This should be populated from the modified field in StudentModule created = models.DateTimeField(db_index=True) state = models.TextField(null=True, blank=True) grade = models.FloatField(null=True, blank=True) max_grade = models.FloatField(null=True, blank=True) @receiver(post_save, sender=StudentModule) def save_history(sender, instance, **kwargs): # pylint: disable=no-self-argument, unused-argument """ Checks the instance's module_type, and creates & saves a StudentModuleHistory entry if the module_type is one that we save. """ if instance.module_type in StudentModuleHistory.HISTORY_SAVING_TYPES: history_entry = StudentModuleHistory(student_module=instance, version=None, created=instance.modified, state=instance.state, grade=instance.grade, max_grade=instance.max_grade) history_entry.save()
class ModelWithCallStckMngrChild(ModelWithCallStackMngr): """child class of ModelWithCallStackMngr """ objects = CallStackManager() child_id_field = models.IntegerField()
class ModelWithCallStackMngr(models.Model): """ Test Model Class with overridden CallStackManager """ objects = CallStackManager() id_field = models.IntegerField()
class ModelAnotherCallStckMngr(models.Model): """ Test Model class that only uses overridden Manager CallStackManager """ objects = CallStackManager() id_field = models.IntegerField()