Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jun 12th, 2012  |  syntax: Python  |  size: 0.65 KB  |  hits: 15  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1.   def __getattribute__(self, name, checkForVersionKey=True):
  2.     """ """
  3.     actualAttribute = models.Model.__getattribute__(self, name)
  4.     if checkForVersionKey:
  5.       try:
  6.         version = Printable.__getattribute__(self, name+"Version", checkForVersionKey=False)
  7.         if version:
  8.           model = Printable.__getattribute__(self, "__class__", checkForVersionKey=False)
  9.           foreignKeyModel = getattr(model, name).field.related.parent_model
  10.           relatedObject = foreignKeyModel.objects.get(copyOfId=actualAttribute.id, version=version)
  11.           return relatedObject
  12.       except AttributeError: pass
  13.                
  14.     return actualAttribute