当一个用户没有经过身份验证时,我需要从下拉列表中隐藏一个选项。你知道吗
class JobPostingListView(ListView):
form_class = JobPostingSearchForm
model = JobPosting
template_name = 'recruiters/job_posting_list.html'
def get_queryset(self):
form = self.form = self.form_class(self.request.GET)
......
def get_context_data(self, **kwargs):
context_data = super(JobPostingListView, self).get_context_data(**kwargs)
if not self.request.user.is_authenticated():
del self.form.fields['date_posted'].choices[1]
#Ok, It shows all except choice one
print self.form.fields['date_posted'].choices
#It doesn't work here because it shows all the choices
print self.form
context_data.update({
'form': self.form
})
return context_data
注意:该代码在视图中,因为我无权访问表单中的is_authenticated
。你知道吗
窗体显示所有选项,我想隐藏选项一。你知道吗
重写
paintComponent
而不是paint
并调用super.paintComponent(g)
为
JPanel
覆盖getPreferredSize()
不要在
paintComponent
方法中创建图像。在构造函数中执行pack()
您的帧,不setSize()
,并且JPanel
的首选大小将得到尊重(通过您的覆盖getPreferredSize()
)你可以在覆盖
getPreferredSize()
之后使用getWidth()
和getHeight()
做所有这些事情,如果没有帮助,发布一个我们可以测试的可运行的例子
相关问题 更多 >
编程相关推荐