Skip to content

Instantly share code, notes, and snippets.

@jlgray
Created June 8, 2012 18:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jlgray/2897395 to your computer and use it in GitHub Desktop.
Save jlgray/2897395 to your computer and use it in GitHub Desktop.
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