Python ChoiceField-基于布尔字段的选择

Python ChoiceField-基于布尔字段的选择,python,django,django-models,django-forms,Python,Django,Django Models,Django Forms,我正在尝试创建一个choicefield,该字段仅显示ProjectManager布尔字段被选中为true的用户。不过,我在想办法做这件事时遇到了一些困难 有点背景。创建用户时,如果用户是项目经理或不是项目经理,则可以选中一个复选框。如果他们选中,我希望下拉选择字段显示所有项目经理(稍后,在创建新项目时) 以下是我的代码片段以提供帮助 Project-Models.py class Project(models.Model): client = models.ForeignKey(Clients

我正在尝试创建一个choicefield,该字段仅显示ProjectManager布尔字段被选中为true的用户。不过,我在想办法做这件事时遇到了一些困难

有点背景。创建用户时,如果用户是项目经理或不是项目经理,则可以选中一个复选框。如果他们选中,我希望下拉选择字段显示所有项目经理(稍后,在创建新项目时)

以下是我的代码片段以提供帮助

Project-Models.py

class Project(models.Model):
client = models.ForeignKey(Clients, related_name='projects')
project_manager = models.ForeignKey(customUser, related_name='Project Manager')
created_by = models.ForeignKey(User, related_name='created_by')
...
客户端-models.py

class Clients(models.Model):

   client_name = models.CharField(max_length=255, verbose_name='Client Name', unique=True)
   ...    

class customUser(User):
   company = models.ForeignKey(Clients, related_name="belongs to")
   pm = models.BooleanField(verbose_name='Project Manager')
项目表单.py

class TimeMaterialsForm(ModelForm):
status = forms.ChoiceField(choices=STATUS_CHOICES)
project_manager = forms.ChoiceField(??)
def __init__(self, *args, **kwargs):
    super(TimeMaterialsForm, self).__init__(*args, **kwargs)
    self.fields['status'].initial = 'T'
    self.fields.keyOrder = ['proj_name', 'client','project_manager','starts_on','desc', 'due_date','completed_on','quote_value','pt_percent','pt_desc','purchase_order','SRED','status', 'notes']
    self.fields['status'].widget=forms.HiddenInput()

...
谢谢大家

史蒂夫这有帮助吗

class TimeMaterialsForm(ModelForm):
   status = forms.ChoiceField(choices=STATUS_CHOICES)
   project_manager = forms.forms.ModelChoiceField(queryset=customUser.objects.filter(pm=True))
   ...  

您使用的是管理员界面还是自定义界面?越来越近,我现在看到了这个错误消息。呈现时发现操作错误:(1054,“字段列表”中的未知列'clients_customuser.pm',当我调用{form}时,它指向我的模板。我有点不清楚…你不想看到拥有
pm
field
true
的客户用户列表吗?我忘了运行syncdb,这就是为什么我会出现错误的原因,谢谢你的帮助!你同步数据库了吗?