Skip to content

Commit

Permalink
pinax#160 fixes an infinite recursion
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisjrn committed Aug 14, 2017
1 parent b5f331b commit 8d8776e
Showing 1 changed file with 1 addition and 24 deletions.
25 changes: 1 addition & 24 deletions symposion/speakers/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,31 +29,8 @@ class SpeakerBase(models.Model):

objects = InheritanceManager()


def subclass(self):
''' Returns the subclassed version of this model '''

try:
# The cached subclass instance so we don't need to query frequently
return self.__subclass_instance__
except AttributeError:
instance = self.__class__.objects.get_subclass(id=self.id)
if type(instance) == type(self):
instance = self
self.__subclass_instance__ = instance
return instance

def __getattr__(self, attr):
''' Overrides getattr to allow us to return subclass properties
from the base class. '''

try:
return super(SpeakerBase, self).__getattr__(attr)
except AttributeError:
if attr == "__subclass_instance__":
raise
subclass = self.subclass()
return getattr(subclass, attr)
return SpeakerBase.objects.get_subclass(id=self.id)

user = models.OneToOneField(User, null=True, related_name="speaker_profile", verbose_name=_("User"))
name = models.CharField(verbose_name=_("Name"), max_length=100,
Expand Down

0 comments on commit 8d8776e

Please sign in to comment.