title: django query multiple tables with foreign key pointing on self
body: <p>lets say I have a model named User, and other models representing actions done by the a user, like "User_clicked", "User_left", "User_ate_cookie" etc. etc.</p>
  
  <p>the User_* models have different fields and inherit from a single abstract class (User_do_something)</p>
  
  <p>my question is this:</p>
  
  <p>what's the django-way of querying ALL the models, from all the relevant tables, that point on a specific user?</p>
  
  <p>eg. I want to do User.get_all_actions() and get a list with mixed type of models in them, containing all the objects that inherit from User_do_something and point on the specific user.</p>
  
  <p><strong>Note: performance is critical.</strong> I don't want to make multiple db queries and combine the list, if possible, I want to do it with a single sql select.</p>
  
  <p>some code to be clear:</p>
  
  <pre><code>class User(models.Model):
      uuid = models.UUIDField(unique=True, default=uuid.uuid4)
      creation_time = models.DateTimeField(auto_now_add=True)
  
      def get_all_actions(self):
          '''
          return a list with ALL the actions this player did.
          '''
          ??????? how do I do this query ???????
  
  class User_do_action(models.Model):
      user = models.ForeignKey(User)
      creation_time = models.DateTimeField(auto_now_add=True)
  
      class Meta:
          abstract = True
  
  class User_click(User_do_action):
      ... some fields
  
  class User_left(User_do_action):
      ... some fields
  
  class User_ate_cookie(User_do_action):
      ... some fields
  
  etc. etc.
  </code></pre>
  
  <p>thanks!</p>