title: How to use one model as source for 'choices' in another model?
body: <p>I have 3 models: User, UserProfile and Programme. User holds the names of all users; </p>
  
  <pre><code>class User(AbstractUser):
      first_name = model.Charfield(...)
      last_name = model.Charfield(...)
      ...
  </code></pre>
  
  <p>UserProfile contains the attributes associated with each user (e.g. sales manager(sm), program manager(pm), delivery manager(dm) etc. </p>
  
  <pre><code>class UserProfile(model.Model):
      user = model.ForeignKey(User, on_delete...)
      sm = model.BooleanField(default = False, editable=True...)
      pm = model.BooleanField(default = False, editable=True...)
      dm = model.BooleanField(default = False, editable=True...)
  </code></pre>
  
  <p>A User may have any combination of UserProfile attributes. For example:
  User-1: sm
  User-2: sm, pm
  User-3: dm
  User-4: sm, dm
  ...</p>
  
  <p>Every programme in Programme must have a user assigned for each of sm, pm, dm so my challenge is finding a way to generate a 'choices' list for each of sm, pm and dm limited to Users with the appropriate attribute. </p>
  
  <pre><code>class Programme(model.Models):
      programme_name = models.Charfield(...)
      AND ESSENTIALLY:
      sm = only users with userprofile.sm = True
      pm = only users with userprofile.pm = True
      dm = only users with userprofile.dm = True
  </code></pre>
  
  <p>I've tried adding a function to UserProfile then referencing it in Programme:</p>
  
  <pre><code>UserProfile(model.Models):
  ....
  
  def get_pm(self):
      pm_list = []
      pm = UserProfile.objects.filter(pm=True)
      for i in pm:
          pm_list.append(i.user.last_name)
          return pm_list
  </code></pre>
  
  <p>and in Programme:</p>
  
  <pre><code>Programme(model.Models):
      pm = models.Charfield(choices=UserProfile.get_pm, ...
  </code></pre>
  
  <p>but this generates the error: 'choices' must be an iterable (e.g., a list or tuple).</p>
  
  <p>Similarly, I've tried adding the same function to Programmes/models.py but this generates the same error.</p>
  
  <p>I know I'm missing the obvious but all help appreciated.</p>