Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class GenericModel(models.Model):
- model_type = models.CharField(max_length=16)
- def __init__(self, *args, **kwargs):
- for related_object in self._meta.get_all_related_objects():
- if not issubclass(related_object.model, self.__class__):
- continue
- self.model_type = '{0}.{1}'.format(self._meta.app_label, related_object.__class__.__name__.lower())
- super(GenericModel, self).__init__(self, *args, **kwargs)
- class SpecializedModel(models.Model):
- pass
Add Comment
Please, Sign In to add comment