0

Say I have the following, Model_1 has 1 integer, Model_2 inherits Model_1 and adds another integer.

class Model_1Manager (models.Manager):
  def create (self, i)
    m = self.model(value1=i)
    m.save()

class Model_1 (models.Model):
  value1 = model.IntegerField()
  objects = Model_1Manager()

class Model_2Manager (Model_1Manager):
  def create (self, i1, i2)
    m = self.model(value1=i1, value2=i2)
    m.save()

class Model_2 (Model_1):
  value2 = model.IntegerField()
  objects = Model_2Manager()

Questions:

  1. Is the create() function in Model_2Manager written correctly as is?
  2. Is there some way for me to call Model_1Manager's create() function?? How would that work?
tshepang
  • 12,111
  • 21
  • 91
  • 136
reedvoid
  • 1,203
  • 3
  • 18
  • 34

1 Answers1

1

Is the create() function in Model_2Manager written correctly as is?

It is.

Is there some way for me to call Model_1Manager's create() function?? How would that work?

Unfortunately in this case Model_1Manager.create() does not do enough to initialize a Model_2, so you should not attempt to call it.

Ignacio Vazquez-Abrams
  • 776,304
  • 153
  • 1,341
  • 1,358
  • Hmm... I guess it also does not make any sense to inherit managers either. What I should probably do is make Model_1 abstract, NOT define a manager for it, and then just define a manager for Model_2. – reedvoid Jun 22 '13 at 03:50