title: How to call call a static function from the same Model in the Model upon initialisation? DJANGO PYTHON
body: <p>So long story short, I have a Car model and a CarVersion model and I want the user to have the ability to choose from the availble car versions saved in the database, through a html select field.</p>
  <p>I cannot understand how to dynamically generate the choices field from the CarVersion model. I have the function, but I cannot call it inside the Car model.</p>
  <p>Here is the code I have so far:</p>
  <pre><code>class Car(models.Model):
      choices = get_choices()
  
      name = models.CharField(max_length=50, unique=True)
      version = models.ForeignKey(CarVersion, choices=get_choices(), on_delete=models.RESTRICT)
      
      @staticmethod
      def get_choices():
          options = CarVersion.objects.all().values_list(&quot;pk&quot;, &quot;name&quot;)
          try:
              if not options:
                  return [(0, &quot;No versions in database. Call your administrator.&quot;)]
          except ProgrammingError:
              return [(0, &quot;No versions in database. Call your administrator.&quot;)]
          return [(1, &quot;Test&quot;)]
  </code></pre>
  <p>I want to call the function <code>get_choices</code> in</p>
  <p><code>version = models.ForeignKey(CarVersion, choices=get_choices(), on_delete=models.RESTRICT)</code>
  but I don't know how to do that while the function is declared to the model. If I define it outside of the model, it works, but there must surely be a better way that im missing, rather than cluttering my models.py file with a bunch of model specific functions.</p>
  <p>P.S.<code>get_choices</code> is not finished but as soon as I can call it, I will deal with it.</p>