Created
June 8, 2012 18:22
-
-
Save jlgray/2897395 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
AbstractBase(models.Model): | |
foo = somefield | |
class Base(AbstractBase): | |
c1 = models.OneToOneField('C1', null=True, blank=True) | |
c2 = models.OneToOneField('C2', null=True, blank=True) | |
def c(self): | |
#only one additional query to get the whole set of data | |
if self.c1_id: | |
return self + c1 | |
if self.c2_id: | |
return self + c2 | |
class C1(models.Model): | |
bar = somefield | |
class C2(models.Model): | |
baz = somefield | |
bs = Base.objects.get(foo='foo') | |
bs.c.foo |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment