title: How to store functions in django models
body: <p>edit: I completely rewrote the question as the original one didn't clearly explain my question</p>
  
  <p>I want to run a function which is specific to each particular model instance.</p>
  
  <p>Ideally I want something like this:</p>
  
  <pre><code>class MyModel(models.Model):
      data = models.CharField(max_length=100)
      perform_unique_action = models.FunctionField() #stores a function specific to this instance
  
  x = MyModel(data='originalx', perform_unique_action=func_for_x)
  x.perform_unique_action() #will do whatever is specified for instance x
  
  y = MyModel(data='originaly', perform_unique_action=func_for_y)
  y.perform_unique_action() #will do whatever is specified for instance y
  </code></pre>
  
  <p>However there is no datatype FunctionField. Normally this would be solvable with inheritance, and creating subclasses of MyModel, maybe like this:</p>
  
  <pre><code>class MyModel(models.Model):
      data = models.CharField(max_length=100)
      perform_unique_action = default_function
  
  class MyModelX(MyModel):
      perform_unique_action = function_X
  
  class MyModelY(MyModel):
      perform_unique_action = function_Y
  
  x = MyModelX(data='originalx')
  x.perform_unique_action() #will do whatever is specified for instance x
  
  y = MyModelY(data='originaly')
  y.perform_unique_action() #will do whatever is specified for instance y
  </code></pre>
  
  <p>Unfortunately, I don't think I can use inheritance because I am trying to access the function this way:</p>
  
  <pre><code>class MyModel(models.Model):
      data = models.CharField(max_length=100)
      perform_unique_action = default_function
  
  class SecondModel(models.Model):
      other_data = models.IntegerField()
      mymodel = models.ForeignKey(MyModel)
  
  secondmodel = SecondModel.objects.get(other_data=3)
  secondmodel.mymodel.perform_unique_action()
  </code></pre>
  
  <p>The problem seems to be that I don't know what type the foreign key is going to be in SecondModel if I override the perform_unique_action in subclasses.</p>
  
  <p>Can I access MyModel from SecondModel as a foreign key and still have a unique function for each instance of MyModel?</p>