Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.