Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
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__):
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):
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.