Created
December 5, 2010 22:04
-
-
Save SmileyChris/729525 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class YourBaseModel(models.Model): | |
@property | |
def child(self): | |
from django.core.exceptions import ObjectDoesNotExist | |
for related_object in self._meta.get_all_related_objects(): | |
if not issubclass(related_object.model, self.__class__): | |
continue | |
try: | |
return getattr(self, related_object.get_accessor_name()) | |
except ObjectDoesNotExist: | |
pass |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment