Guest User

Untitled

a guest
Oct 19th, 2018
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.50 KB | None | 0 0
  1. AbstractBase(models.Model):
  2. foo = somefield
  3.  
  4. class Base(AbstractBase):
  5. c1 = models.OneToOneField('C1', null=True, blank=True)
  6. c2 = models.OneToOneField('C2', null=True, blank=True)
  7.  
  8. def c(self):
  9. #only one additional query to get the whole set of data
  10. if self.c1_id:
  11. return self + c1
  12. if self.c2_id:
  13. return self + c2
  14.  
  15.  
  16. class C1(models.Model):
  17. bar = somefield
  18.  
  19. class C2(models.Model):
  20. baz = somefield
  21.  
  22. bs = Base.objects.get(foo='foo')
  23. bs.c.foo
Add Comment
Please, Sign In to add comment