您可以在 init中* 自定义表格 *
class ExcludedDateForm(ModelForm): class meta: model = models.ExcludedDate exclude = ('user', 'recurring',) def __init__(self, user=None, **kwargs): super(ExcludedDateForm, self).__init__(**kwargs) if user: self.fields['category'].queryset = models.Category.objects.filter(user=user)
在视图中,在构建表单时,除了标准表单参数外,您还将指定当前用户:
form = ExcludedDateForm(user=request.user)
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)