Skip to content

Instantly share code, notes, and snippets.

@monokrome
Created December 20, 2010 10:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save monokrome/748217 to your computer and use it in GitHub Desktop.
Save monokrome/748217 to your computer and use it in GitHub Desktop.
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment