Skip to content

Instantly share code, notes, and snippets.

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